Verified Commit b30fe98d authored by godotislate's avatar godotislate
Browse files

feat: #3015812 Introduce new Theme extension object and properly deprecate...

feat: #3015812 Introduce new Theme extension object and properly deprecate REGIONS_VISIBLE and REGIONS_ALL

By: alexpott
By: andypost
By: phenaproxima
By: markhalliwell
By: vacho
By: voleger
By: berdir
By: hardik_patel_12
By: nikitagupta
By: jofitz
By: smustgrave
By: quietone
By: viappidu
By: ameymudras
By: claudiu.cristea
By: ravi.shankar
By: suresh prabhu parkala
By: akram khan
By: nicxvan
By: xjm
By: godotislate
parent 88187a5e
Loading
Loading
Loading
Loading
Loading
+0 −12
Changes for core/.phpstan-baseline.php: 0 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -10807,12 +10807,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/block/src/BlockListBuilder.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\block\\\\BlockListBuilder\\:\\:systemRegionList\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/block/src/BlockListBuilder.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\block\\\\BlockListBuilder\\:\\:validateForm\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
@@ -10861,12 +10855,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/block/src/EventSubscriber/BlockPageDisplayVariantSubscriber.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\block\\\\Form\\\\BlockDeleteForm\\:\\:systemRegionList\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/block/src/Form/BlockDeleteForm.php',
];
$ignoreErrors[] = [
	'message' => '#^Parameter \\#2 \\$callback of function uasort expects callable\\(Drupal\\\\Core\\\\Entity\\\\EntityInterface, Drupal\\\\Core\\\\Entity\\\\EntityInterface\\)\\: int, Closure\\(Drupal\\\\block\\\\BlockInterface, Drupal\\\\block\\\\BlockInterface\\)\\: int\\<\\-1, 1\\> given\\.$#',
	'identifier' => 'argument.type',
+16 −2
Changes for core/lib/Drupal/Core/Extension/ExtensionList.php: 16 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -311,9 +311,10 @@ protected function doList() {
    $extensions = $this->doScanExtensions();

    // Read info files for each extension.
    foreach ($extensions as $extension) {
    foreach ($extensions as $name => $extension) {
      $extension->info = $this->createExtensionInfo($extension);

      $extension = $this->subClassExtension($extension);
      $extensions[$name] = $extension;
      // Invoke hook_system_info_alter() to give installed modules a chance to
      // modify the data in the .info.yml files if necessary.
      $this->moduleHandler->alter('system_info', $extension->info, $extension, $this->type);
@@ -322,6 +323,19 @@ protected function doList() {
    return $extensions;
  }

  /**
   * Allows subclasses to convert the extension into a specific subclass.
   *
   * @param \Drupal\Core\Extension\Extension $extension
   *   The extension.
   *
   * @return \Drupal\Core\Extension\Extension
   *   Either the unchanged Extension object or a subclass of Extension.
   */
  protected function subClassExtension(Extension $extension): Extension {
    return $extension;
  }

  /**
   * Returns information about a specified extension.
   *
+78 −0
Changes for core/lib/Drupal/Core/Extension/Theme.php: 78 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Core\Extension;

use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * The Theme extension object.
 *
 * Extending this class is not supported and no BC is provided for subclasses.
 *
 * @see \Drupal\Core\Extension\ThemeExtensionList::doList()
 *
 * @todo https://www.drupal.org/project/drupal/issues/3026232 Replace public
 *   and dynamic properties with methods.
 *
 * @final
 */
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());
  }

}
+7 −0
Changes for core/lib/Drupal/Core/Extension/ThemeExtensionList.php: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -243,6 +243,13 @@ protected function createExtensionInfo(Extension $extension) {
    return $info;
  }

  /**
   * {@inheritdoc}
   */
  protected function subClassExtension(Extension $extension): Theme {
    return new Theme($this->root, $extension->getPathname(), $extension->info, $extension->getExtensionFilename());
  }

  /**
   * {@inheritdoc}
   */
+2 −2
Changes for core/lib/Drupal/Core/Extension/ThemeHandler.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public function listInfo() {
          // file system any call to ::getTheme() will result in an exception
          // and an error being logged. Ignoring the problem here allows the
          // theme system to fix itself while updating.
          if (isset($list[$theme])) {
          if (isset($list[$theme]) && $list[$theme] instanceof Theme) {
            $this->addTheme($list[$theme]);
          }
        }
@@ -88,7 +88,7 @@ public function listInfo() {
  /**
   * {@inheritdoc}
   */
  public function addTheme(Extension $theme) {
  public function addTheme(Theme $theme) {
    if (!empty($theme->info['libraries'])) {
      foreach ($theme->info['libraries'] as $library => $name) {
        $theme->libraries[$library] = $name;
Loading