class Theme

Same name in this branch
  1. 11.x core/lib/Drupal/Core/Updater/Theme.php \Drupal\Core\Updater\Theme
Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Updater/Theme.php \Drupal\Core\Updater\Theme
  2. 9 core/lib/Drupal/Core/Updater/Theme.php \Drupal\Core\Updater\Theme
  3. 8.9.x core/lib/Drupal/Core/Updater/Theme.php \Drupal\Core\Updater\Theme
  4. main core/lib/Drupal/Core/Extension/Theme.php \Drupal\Core\Extension\Theme

The Theme extension object.

Extending this class is not supported and no BC is provided for subclasses.

@todo https://www.drupal.org/project/drupal/issues/3026232 Replace public and dynamic properties with methods.

@final

Hierarchy

Expanded class hierarchy of Theme

See also

\Drupal\Core\Extension\ThemeExtensionList::doList()

3 files declare their use of Theme
EnabledExtensionsValidatorTest.php in core/modules/package_manager/tests/src/Kernel/EnabledExtensionsValidatorTest.php
system.module in core/modules/system/system.module
ThemeHandlerTest.php in core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php
259 string references to 'Theme'
admin.info.yml in core/themes/admin/admin.info.yml
core/themes/admin/admin.info.yml
AdminDemoNegotiator::determineActiveTheme in core/modules/block/src/Theme/AdminDemoNegotiator.php
Determine the active theme for the request.
AssertPageCacheContextsAndTagsTrait::assertCacheContexts in core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php
Ensures that some cache contexts are present in the current response.
AssetControllerBase::deliver in core/modules/system/src/Controller/AssetControllerBase.php
Generates an aggregate, given a filename.
big_pipe_test_theme.info.yml in core/modules/big_pipe/tests/themes/big_pipe_test_theme/big_pipe_test_theme.info.yml
core/modules/big_pipe/tests/themes/big_pipe_test_theme/big_pipe_test_theme.info.yml

... See full list

File

core/lib/Drupal/Core/Extension/Theme.php, line 21

Namespace

Drupal\Core\Extension
View source
class Theme extends Extension {
  
  /**
   * Constructs a new Theme object.
   *
   * @param string $root
   *   The app root.
   * @param string $pathname
   *   The relative path and filename of the extension's info file; e.g.,
   *   'core/themes/olivero/olivero.info.yml'.
   * @param array $info
   *   The info array parsed from the theme's .info.yml file.
   * @param string|null $filename
   *   (optional) The filename of the main extension file; e.g., olivero.theme.
   */
  public function __construct(string $root, string $pathname, array $info, ?string $filename = NULL) {
    parent::__construct($root, 'theme', $pathname, $filename);
    $this->info = $info;
  }
  
  /**
   * Lists all the theme's regions.
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup[]
   *   An array of human-readable region names keyed by machine names.
   */
  public function listAllRegions() : array {
    return array_map(static function ($label) {
      // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString
      return new TranslatableMarkup($label);
    }, $this->info['regions']);
  }
  
  /**
   * Lists all the theme's visible regions.
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup[]
   *   An array of human-readable region names keyed by machine names.
   */
  public function listVisibleRegions() : array {
    // List only regions that do not appear in the 'regions_hidden' key.
    return array_diff_key($this->listAllRegions(), array_flip($this->info['regions_hidden']));
  }
  
  /**
   * Gets the name of the default region for the theme.
   *
   * @return string
   *   The machine name of the default region.
   */
  public function getDefaultRegion() : string {
    return (string) key($this->listVisibleRegions());
  }

}

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