function _block_rehash

Returns an array of block class instances by theme.

Parameters

$theme: The theme to rehash blocks for. If not provided, defaults to the currently used theme.

Return value

Blocks currently exported by modules.

3 calls to _block_rehash()
BlockListController::load in drupal/core/modules/block/lib/Drupal/block/BlockListController.php
Overrides \Drupal\Core\Config\Entity\ConfigEntityListController::load().
block_rebuild in drupal/core/modules/block/block.module
Implements hook_rebuild().
hook_rebuild in drupal/core/modules/system/system.api.php
Rebuild data based upon refreshed caches.

File

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

Code

function _block_rehash($theme = NULL) {
  $theme = $theme ? $theme : config('system.theme')
    ->get('default');
  $regions = system_region_list($theme);
  $blocks = entity_load_multiple_by_properties('block', array(
    'theme' => $theme,
  ));
  foreach ($blocks as $block_id => $block) {
    $region = $block
      ->get('region');
    $status = $block
      ->status();

    // Disable blocks in invalid regions.
    if (!empty($region) && $region != BLOCK_REGION_NONE && !isset($regions[$region]) && $status) {
      drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array(
        '%info' => $block_id,
        '%region' => $region,
      )), 'warning');

      // Disabled modules are moved into the BLOCK_REGION_NONE later so no
      // need to move the block to another region.
      $block
        ->disable()
        ->save();
    }

    // Set region to none if not enabled.
    if (!$status) {
      $block
        ->set('region', BLOCK_REGION_NONE);
      $block
        ->save();
    }
  }
  return $blocks;
}