ThemeRegistry example

/** * Returns the incomplete, runtime theme registry. * * @return \Drupal\Core\Utility\ThemeRegistry * A shared instance of the ThemeRegistry class, provides an ArrayObject * that allows it to be accessed with array syntax and isset(), and is more * lightweight than the full registry. */
  public function getRuntime() {
    $this->init($this->themeName);
    if (!isset($this->runtimeRegistry[$this->theme->getName()])) {
      $this->runtimeRegistry[$this->theme->getName()] = new ThemeRegistry('theme_registry:runtime:' . $this->theme->getName()$this->runtimeCache ?: $this->cache, $this->lock, ['theme_registry']$this->moduleHandler->isLoaded());
    }
    return $this->runtimeRegistry[$this->theme->getName()];
  }

  /** * Persists the theme registry in the cache backend. */
  protected function setCache() {
    $this->cache->set('theme_registry:' . $this->theme->getName()$this->registry[$this->theme->getName()], Cache::PERMANENT, ['theme_registry']);
  }

  

  public function testRaceCondition() {
    // The theme registry is not marked as persistable in case we don't have a     // proper request.     \Drupal::request()->setMethod('GET');
    $cid = 'test_theme_registry';

    // Directly instantiate the theme registry, this will cause a base cache     // entry to be written in __construct().     $cache = \Drupal::cache();
    $lock_backend = \Drupal::lock();
    $registry = new ThemeRegistry($cid$cache$lock_backend['theme_registry']$this->container->get('module_handler')->isLoaded());

    $this->assertNotEmpty(\Drupal::cache()->get($cid), 'Cache entry was created.');

    // Trigger a cache miss for an offset.     $this->assertNotEmpty($registry->get('theme_test_template_test'), 'Offset was returned correctly from the theme registry.');
    // This will cause the ThemeRegistry class to write an updated version of     // the cache entry when it is destroyed, usually at the end of the request.     // Before that happens, manually delete the cache entry we created earlier     // so that the new entry is written from scratch.     \Drupal::cache()->delete($cid);

    
Home | Imprint | This part of the site doesn't use cookies.