development

Drupal 8 - get blocks assigned to a region

Problem: There is no specific function in Drupal 8 which we can use to get all blocks assigned to a region. We used to have a function called block_get_blocks_by_region in Drupal 7 to do this

 

Solution : Although we don't have a specific function we have the tools in Drupal 8 s Object oriented hierarchy to do the same. Here is the code

 

function my_module_get_blocks_by_region($region) {

  $blocks = \Drupal::entityTypeManager()

    ->getStorage('block')->loadByProperties([

Setting up debug mode on Drupal 8

  1. First copy sites/example.settings.local.php to default/settings.local.php
  2. Now uncomment the following lines in default/settings.php
    # if (file_exists(__DIR__ . '/settings.local.php')) {
    #   include __DIR__ . '/settings.local.php';
    # }
  3. Now debugging is set. You also can use the following command
    drupal routing:debug <route name>
    This command will give the user information regarding a specific route