function ThemeRegistry::__construct

Same name and namespace in other branches
  1. 7.x includes/theme.inc \ThemeRegistry::__construct()
  2. 9 core/lib/Drupal/Core/Utility/ThemeRegistry.php \Drupal\Core\Utility\ThemeRegistry::__construct()
  3. 8.9.x core/lib/Drupal/Core/Utility/ThemeRegistry.php \Drupal\Core\Utility\ThemeRegistry::__construct()
  4. 10 core/lib/Drupal/Core/Utility/ThemeRegistry.php \Drupal\Core\Utility\ThemeRegistry::__construct()

Constructs a ThemeRegistry object.

Parameters

string $cid: The cid for the array being cached.

\Drupal\Core\Cache\CacheBackendInterface $cache: The cache backend.

\Drupal\Core\Lock\LockBackendInterface $lock: The lock backend.

array $tags: (optional) The tags to specify for the cache item.

bool $modules_loaded: Whether all modules have already been loaded.

Overrides CacheCollector::__construct

File

core/lib/Drupal/Core/Utility/ThemeRegistry.php, line 51

Class

ThemeRegistry
Builds the run-time theme registry.

Namespace

Drupal\Core\Utility

Code

public function __construct($cid, CacheBackendInterface $cache, LockBackendInterface $lock, $tags = [], $modules_loaded = FALSE) {
    $this->cid = $cid;
    $this->cache = $cache;
    $this->lock = $lock;
    $this->tags = $tags;
    $this->persistable = $modules_loaded && \Drupal::hasRequest() && \Drupal::request()->isMethod('GET');
    // @todo Implement lazy-loading.
    $this->cacheLoaded = TRUE;
    if ($this->persistable && ($cached = $this->cache
        ->get($this->cid))) {
        $this->storage = $cached->data;
    }
    else {
        // If there is no runtime cache stored, fetch the full theme registry,
        // but then initialize each value to NULL. This allows offsetExists()
        // to function correctly on non-registered theme hooks without triggering
        // a call to resolveCacheMiss().
        $this->storage = $this->initializeRegistry();
        foreach (array_keys($this->storage) as $key) {
            $this->persist($key);
        }
        // RegistryTest::testRaceCondition() ensures that the cache entry is
        // written on the initial construction of the theme registry.
        $this->updateCache();
    }
}

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