getBaseThemeExtensions example


  private function maybeNegotiateByTheme(array $candidates): ?string {
    // Prepare the error message.     $theme_name = $this->activeTheme->getName();
    // Let's do theme based negotiation.     $base_theme_names = array_map(
      static fn(Extension $extension) => $extension->getName(),
      $this->activeTheme->getBaseThemeExtensions()
    );
    $considered_themes = [$theme_name, ...$base_theme_names];
    // Only consider components in the theme hierarchy tree.     $candidates = array_filter(
      $candidates,
      static fn(array $definition) => $definition['extension_type'] === ExtensionType::Theme
        && in_array($definition['provider']$considered_themes, TRUE)
    );
    if (empty($candidates)) {
      return NULL;
    }
    
public function testMaintenanceTheme() {
    $this->setSetting('maintenance_theme', 'test_subtheme');
    // Get the maintenance theme loaded.     drupal_maintenance_theme();

    // Do we have an active theme?     $this->assertTrue(\Drupal::theme()->hasActiveTheme());

    $active_theme = \Drupal::theme()->getActiveTheme();
    $this->assertEquals('test_subtheme', $active_theme->getName());

    $base_themes = $active_theme->getBaseThemeExtensions();
    $base_theme_names = array_keys($base_themes);
    $this->assertSame(['test_basetheme']$base_theme_names);
  }

}
$this->processExtension($cache$module, 'module', $module$this->moduleList->getPath($module));
      });
      // Only cache this registry if all modules are loaded.       if ($this->moduleHandler->isLoaded()) {
        $this->cache->set("theme_registry:build:modules", $cache, Cache::PERMANENT, ['theme_registry']);
      }
    }

    // Process each base theme.     // Ensure that we start with the root of the parents, so that both CSS files     // and preprocess functions comes first.     foreach (array_reverse($this->theme->getBaseThemeExtensions()) as $base) {
      // If the base theme uses a theme engine, process its hooks.       $base_path = $base->getPath();
      if ($this->theme->getEngine()) {
        $this->processExtension($cache$this->theme->getEngine(), 'base_theme_engine', $base->getName()$base_path);
      }
      $this->processExtension($cache$base->getName(), 'base_theme', $base->getName()$base_path);
    }

    // And then the same thing, but for the theme.     if ($this->theme->getEngine()) {
      $this->processExtension($cache$this->theme->getEngine(), 'theme_engine', $this->theme->getName()$this->theme->getPath());
    }
return $active_theme;
  }

  /** * {@inheritdoc} */
  public function loadActiveTheme(ActiveTheme $active_theme) {
    // Initialize the theme.     if ($active_theme->getEngine()) {
      // Include the engine.       include_once $this->root . '/' . $active_theme->getOwner();
      foreach ($active_theme->getBaseThemeExtensions() as $base) {
        $base->load();
      }
      $active_theme->getExtension()->load();
    }
    else {
      // include non-engine theme files       foreach ($active_theme->getBaseThemeExtensions() as $base) {
        // Include the theme file or the engine.         if ($base->owner) {
          include_once $this->root . '/' . $base->owner;
        }
      }


    /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form */
    $exposed_form = $this->display_handler->getPlugin('exposed_form');
    $exposed_form->preRender($this->result);

    $module_handler = \Drupal::moduleHandler();

    // @todo In the long run, it would be great to execute a view without     // the theme system at all. See https://www.drupal.org/node/2322623.     $active_theme = \Drupal::theme()->getActiveTheme();
    $themes = array_keys($active_theme->getBaseThemeExtensions());
    $themes[] = $active_theme->getName();

    // Check for already-cached output.     /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
    if (!empty($this->live_preview)) {
      $cache = Views::pluginManager('cache')->createInstance('none');
    }
    else {
      $cache = $this->display_handler->getPlugin('cache');
    }

    
$this->themeManager = $this->container->get('theme.manager');
  }

  /** * Tests opting out of Stable 9 by setting the base theme to false. */
  public function testWildWest() {
    $this->themeInstaller->install(['test_wild_west']);
    $this->config('system.theme')->set('default', 'test_wild_west')->save();
    $theme = $this->themeManager->getActiveTheme();
    /** @var \Drupal\Core\Theme\ActiveTheme $base_theme */
    $base_themes = $theme->getBaseThemeExtensions();
    $this->assertEmpty($base_themes, 'No base theme is set when a theme has opted out of using Stable 9.');
  }

}

  public function testPostProcessExtension($defined_functions$hooks$expected) {
    static::$functions['user'] = $defined_functions;

    $theme = $this->prophesize(ActiveTheme::class);
    $theme->getBaseThemeExtensions()->willReturn([]);
    $theme->getName()->willReturn('test');
    $theme->getEngine()->willReturn('twig');

    $this->moduleHandler->expects($this->atLeastOnce())
      ->method('getModuleList')
      ->willReturn([]);

    $class = new \ReflectionClass(Registry::class);
    $reflection_method = $class->getMethod('postProcessExtension');
    $reflection_method->invokeArgs($this->registry, [&$hooks$theme->reveal()]);

    
    if (is_array($type)) {
      $extra_types = $type;
      $type = array_shift($extra_types);
      // Allow if statements in this function to use the faster isset() rather       // than !empty() both when $type is passed as a string, or as an array with       // one item.       if (empty($extra_types)) {
        unset($extra_types);
      }
    }

    $theme_keys = array_keys($theme->getBaseThemeExtensions());
    $theme_keys[] = $theme->getName();
    $functions = [];
    foreach ($theme_keys as $theme_key) {
      $function = $theme_key . '_' . $type . '_alter';
      if (function_exists($function)) {
        $functions[] = $function;
      }
      if (isset($extra_types)) {
        foreach ($extra_types as $extra_type) {
          $function = $theme_key . '_' . $extra_type . '_alter';
          if (function_exists($function)) {
            
Home | Imprint | This part of the site doesn't use cookies.