isLoaded example


  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);

    
public function getClassPath($name)
    {
        $name = $this->_formatName($name);
        if ($this->_useStaticRegistry
            && !empty(self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name])
        ) {
            return self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name];
        } elseif (!empty($this->_loadedPluginPaths[$name])) {
            return $this->_loadedPluginPaths[$name];
        }

        if ($this->isLoaded($name)) {
            $class = $this->getClassName($name);
            $r     = new ReflectionClass($class);
            $path  = $r->getFileName();
            if ($this->_useStaticRegistry) {
                self::$_staticLoadedPluginPaths[$this->_useStaticRegistry][$name] = $path;
            } else {
                $this->_loadedPluginPaths[$name] = $path;
            }
            return $path;
        }

        
public function get() {
    $this->init($this->themeName);
    if (isset($this->registry[$this->theme->getName()])) {
      return $this->registry[$this->theme->getName()];
    }
    if ($cache = $this->cache->get('theme_registry:' . $this->theme->getName())) {
      $this->registry[$this->theme->getName()] = $cache->data;
    }
    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()];
  }

  /** * 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. */
/** * {@inheritdoc} */
  public function render($hook, array $variables) {
    static $default_attributes;

    $active_theme = $this->getActiveTheme();

    // If called before all modules are loaded, we do not necessarily have a     // full theme registry to work with, and therefore cannot process the theme     // request properly. See also \Drupal\Core\Theme\Registry::get().     if (!$this->moduleHandler->isLoaded() && !defined('MAINTENANCE_MODE')) {
      throw new \Exception('The theme implementations may not be rendered until all modules are loaded.');
    }

    $theme_registry = $this->themeRegistry->getRuntime();

    // If an array of hook candidates were passed, use the first one that has an     // implementation.     if (is_array($hook)) {
      foreach ($hook as $candidate) {
        if ($theme_registry->has($candidate)) {
          break;
        }
$module_handler->addModule('module_handler_test_added', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_added');
    $module_handler->reload();
  }

  /** * Tests isLoaded accessor. * * @covers ::isLoaded */
  public function testIsLoaded() {
    $module_handler = $this->getModuleHandler();
    $this->assertFalse($module_handler->isLoaded());
    $module_handler->loadAll();
    $this->assertTrue($module_handler->isLoaded());
  }

  /** * Confirm we get back the modules set in the constructor. * * @covers ::getModuleList */
  public function testGetModuleList() {
    $this->assertEquals($this->getModuleHandler()->getModuleList()[
      

    public function loadClass($class$path = null)
    {
        if (\is_array($class) && $class !== []) {
            return min(array_map([$this, __METHOD__]$class));
        }
        if (!\is_string($class)) {
            throw new Enlight_Exception('Class name must be a string');
        }
        $class = ltrim($class, self::DEFAULT_SEPARATOR);
        if (!$this->isLoaded($class)) {
            if ($path !== null) {
                $this->loadFile($path);

                return true;
            }
            $path = $this->getClassPath($class);
            if ($path === null) {
                return false;
            }
            $this->loadFile($path, false);
        }

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