block_rebuild

block_rebuild()

Implements hook_rebuild().

File

core/modules/block/block.module, line 139
Controls the visual building blocks a page is constructed with.

Code

function block_rebuild() {
  foreach (\Drupal::service('theme_handler')->listInfo() as $theme => $data) {
    if ($data->status) {
      $regions = system_region_list($theme);
      /** @var \Drupal\block\BlockInterface[] $blocks */
      $blocks = \Drupal::entityTypeManager()->getStorage('block')->loadByProperties(['theme' => $theme]);
      foreach ($blocks as $block_id => $block) {
        // Disable blocks in invalid regions.
        $region = $block->getRegion();
        if ($region !== BlockInterface::BLOCK_REGION_NONE) {
          if (!empty($region) && !isset($regions[$region]) && $block->status()) {
            drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block_id, '%region' => $region]), 'warning');
            $block->disable();
          }
          // Set region to none if not enabled.
          if (!$block->status()) {
            $block->setRegion(BlockInterface::BLOCK_REGION_NONE);
            $block->save();
          }
        }
      }
    }
  }
}
doc_Drupal
2016-10-29 08:47:54
Comments
Leave a Comment

Please login to continue.