function Registry::get

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Theme/Registry.php \Drupal\Core\Theme\Registry::get()
  2. 8.9.x core/lib/Drupal/Core/Theme/Registry.php \Drupal\Core\Theme\Registry::get()
  3. 11.x core/lib/Drupal/Core/Theme/Registry.php \Drupal\Core\Theme\Registry::get()

Returns the complete theme registry from cache or rebuilds it.

Return value

array The complete theme registry data array.

See also

Registry::$registry

File

core/lib/Drupal/Core/Theme/Registry.php, line 247

Class

Registry
Defines the theme registry service.

Namespace

Drupal\Core\Theme

Code

public function get() {
  $this->init($this->themeName);
  if ($cached = $this->cacheGet()) {
    return $cached;
  }
  // If called from inside a Fiber, suspend it, this may allow another code
  // path to begin an asynchronous operation before we do the CPU-intensive
  // task of building the theme registry.
  if (\Fiber::getCurrent() !== NULL) {
    \Fiber::suspend();
    // When the Fiber is resumed, check the cache again since it may have been
    // built in the meantime, either in this process or via a different
    // request altogether.
    if ($cached = $this->cacheGet()) {
      return $cached;
    }
  }
  // Some theme hook implementations such as the one in Views request a lot of
  // information such as field schemas. These might be broken until an update
  // is run, so we need to build a limited registry while on update.php.
  if ($this->kernel instanceof UpdateKernel) {
    $module_list = $this->moduleHandler
      ->getModuleList();
    $filter_list = array_intersect_key($module_list, [
      'system' => TRUE,
    ]);
    // Call ::build() with only the system module and then revert.
    $this->moduleHandler
      ->setModuleList($filter_list);
    $this->build();
    $this->moduleHandler
      ->setModuleList($module_list);
    // We might have poisoned the cache with only info from 'system'.
    $this->cache
      ->delete("theme_registry:build:modules");
  }
  else {
    $this->build();
    // Only persist it if all modules are loaded to ensure it is complete.
    if ($this->moduleHandler
      ->isLoaded()) {
      $this->setCache();
    }
  }
  return $this->registry[$this->theme
    ->getName()];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.