Example #1
0
/**
 * Rebuild data based upon refreshed caches.
 *
 * This hook allows your module to rebuild its data based on the latest/current
 * module data. It runs after hook_cache_flush() and after all module data has
 * been updated.
 *
 * This hook is only invoked after the system has been completely cleared;
 * i.e., all previously cached data is known to be gone and every API in the
 * system is known to return current information, so your module can safely rely
 * on all available data to rebuild its own.
 *
 * @see hook_cache_flush()
 * @see drupal_flush_all_caches()
 */
function hook_rebuild()
{
    $themes = \Drupal::service('theme_handler')->listInfo();
    foreach ($themes as $theme) {
        _block_rehash($theme->getName());
    }
}
 /**
  * Reset theme to default so we can play with blocks
  */
 function initTheme() {
   global $theme, $theme_key;
   unset($theme);
   unset($theme_key);
   init_theme();
   _block_rehash();
 }
 /**
  * {@inheritdoc}
  */
 public function load()
 {
     // If no theme was specified, use the current theme.
     if (!$this->theme) {
         $this->theme = $GLOBALS['theme'];
     }
     // Store the region list.
     $this->regions = system_region_list($this->theme, REGIONS_VISIBLE);
     // Load only blocks for this theme, and sort them.
     // @todo Move the functionality of _block_rehash() out of the listing page.
     $entities = _block_rehash($this->theme);
     // Sort the blocks using \Drupal\block\Entity\Block::sort().
     uasort($entities, array($this->entityType->getClass(), 'sort'));
     return $entities;
 }
 /**
  * Disables the language switcher blocks.
  *
  * @param array $language_types
  *   An array containing all language types whose language switchers need to
  *   be disabled.
  */
 protected function disableLanguageSwitcher(array $language_types)
 {
     $blocks = _block_rehash();
     foreach ($language_types as $language_type) {
         foreach ($blocks as $block) {
             if (strpos($block->id, 'language_switcher_' . substr($language_type, 9)) !== FALSE) {
                 $block->delete();
             }
         }
     }
 }
Example #5
0
/**
 * Rebuild data based upon refreshed caches.
 *
 * This hook allows your module to rebuild its data based on the latest/current
 * module data. It runs after hook_cache_flush() and after all module data has
 * been updated.
 *
 * This hook is only invoked after the system has been completely cleared;
 * i.e., all previously cached data is known to be gone and every API in the
 * system is known to return current information, so your module can safely rely
 * on all available data to rebuild its own.
 *
 * @see hook_cache_flush()
 * @see drupal_flush_all_caches()
 */
function hook_rebuild()
{
    $themes = list_themes();
    foreach ($themes as $theme) {
        _block_rehash($theme->getName());
    }
}
Example #6
0
 /**
  * Implements \SiteAudit\Check\Abstract\calculateScore().
  */
 public function calculateScore()
 {
     $blocks = _block_rehash($this->registry['theme_default']);
     // Only check enabled blocks.
     foreach ($blocks as $bid => $block) {
         if ($block['region'] == -1) {
             unset($blocks[$bid]);
         }
     }
     // Make sure there are blocks to check.
     if (empty($blocks)) {
         $this->abort = TRUE;
         return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN;
     }
     // Human readable order.
     usort($blocks, function ($a, $b) {
         return strcmp($a['module'] . $a['delta'], $b['module'] . $b['delta']);
     });
     $this->registry['blocks'] = array();
     foreach ($blocks as $block) {
         $this->registry['blocks'][] = array('module' => $block['module'], 'info' => $block['info'], 'state' => $this->getCacheStateLabel($block['cache']));
     }
     return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO;
 }