D8 snippets

Search Drupal all source code

http://grep.xnddx.ru/ 


Programmtically load a views block

       use Drupal\block\Entity;

        $block = \Drupal\block\Entity\Block::load('views_block__who_s_online_who_s_online_block');

        $block_content = \Drupal::entityManager()

          ->getViewBuilder('block')

          ->view($block);

Make sure the block is loaded via block management in the region via UI and keep it disabled.

https://drupal.stackexchange.com/questions/171686/how-can-i-programmatically-display-a-block 

Useful twig functions wrapper

https://www.drupal.org/project/twig_tweak

Machine name of the block

Click "Configure" on the specific block in block management page and you can get the machine name of the block.

Example:

views_block__e_books_home_e_books_home_block 

To get the list of all blocks

> bin/drush ev "print_r(array_keys(\Drupal::service('plugin.manager.block')->getDefinitions()));"

Custom fields to content types:

https://www.drupal.org/docs/drupal-apis/entity-api/programming-custom-fields-into-your-content-type 

View all the libraries in a page

https://git.drupalcode.org/project/libraries_debug/-/blob/8.x-1.x/libraries_debug.module

useful links:

https://gist.github.com/bdlangton/e826276a0c78d9a89d8dec23dd0c7683

https://stefvanlooveren.me/

https://agaric.coop/blog/creating-links-code-drupal-8

Routes:

Routes can be altered with RouteSubscriberBase


Comments

Popular posts from this blog

Programatically create layout builder section in Drupal

Code quality analysis of Drupal. Can I use Sonar?

Set up Drupal7 to Drupal8 migration in simple steps (using Drush)