From 1e80a22b06267e9aa6833ccebd4b6a2e61878e5d Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Fri, 15 Mar 2024 17:56:10 +0000
Subject: [PATCH] Issue #2972153 by dimitriskr, alexpott, smustgrave, andypost,
 kostyashupenko: Deprecate ThemeHandlerInterface::getBaseThemes and remove
 usages from core

---
 .../Core/Extension/ThemeExtensionList.php     |  6 ++++
 .../Drupal/Core/Extension/ThemeHandler.php    |  1 +
 .../Core/Extension/ThemeHandlerInterface.php  |  5 +++
 .../Core/Extension/ThemeExtensionListTest.php | 35 +++++++++++++++++--
 4 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/core/lib/Drupal/Core/Extension/ThemeExtensionList.php b/core/lib/Drupal/Core/Extension/ThemeExtensionList.php
index e3a427f9c831..a73782a61e0a 100644
--- a/core/lib/Drupal/Core/Extension/ThemeExtensionList.php
+++ b/core/lib/Drupal/Core/Extension/ThemeExtensionList.php
@@ -210,8 +210,14 @@ protected function fillInSubThemeData(array &$themes, array $sub_themes) {
    * @return array
    *   Returns an array of all of the theme's ancestors; the first element's
    *   value will be NULL if an error occurred.
+   *
+   * @deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. There
+   *   is no direct replacement.
+   *
+   * @see https://www.drupal.org/node/3413187
    */
   public function getBaseThemes(array $themes, $theme) {
+    @trigger_error("\Drupal\Core\Extension\ThemeExtensionList::getBaseThemes() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. There is no direct replacement. See https://www.drupal.org/node/3413187", E_USER_DEPRECATED);
     return $this->doGetBaseThemes($themes, $theme);
   }
 
diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php
index cb6037c818ba..792be25ab6da 100644
--- a/core/lib/Drupal/Core/Extension/ThemeHandler.php
+++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php
@@ -133,6 +133,7 @@ public function rebuildThemeData() {
    * {@inheritdoc}
    */
   public function getBaseThemes(array $themes, $theme) {
+    @trigger_error("\Drupal\Core\Extension\ThemeHandlerInterface::getBaseThemes() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. There is no direct replacement. See https://www.drupal.org/node/3413187", E_USER_DEPRECATED);
     return $this->themeList->getBaseThemes($themes, $theme);
   }
 
diff --git a/core/lib/Drupal/Core/Extension/ThemeHandlerInterface.php b/core/lib/Drupal/Core/Extension/ThemeHandlerInterface.php
index 20d3db78957f..55fab77ee532 100644
--- a/core/lib/Drupal/Core/Extension/ThemeHandlerInterface.php
+++ b/core/lib/Drupal/Core/Extension/ThemeHandlerInterface.php
@@ -98,6 +98,11 @@ public function rebuildThemeData();
    * @return array
    *   Returns an array of all of the theme's ancestors; the first element's
    *   value will be NULL if an error occurred.
+   *
+   * @deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. There
+   *    is no direct replacement.
+   *
+   * @see https://www.drupal.org/node/3413187
    */
   public function getBaseThemes(array $themes, $theme);
 
diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php
index 0f112489526b..118f884713ab 100644
--- a/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php
+++ b/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php
@@ -116,7 +116,9 @@ public function testRebuildThemeDataWithThemeParents() {
    * @param array $expected
    *   The expected base themes.
    *
-   * @dataProvider providerTestGetBaseThemes
+   * @dataProvider providerTestDoGetBaseThemes
+   *
+   * @group legacy
    */
   public function testGetBaseThemes(array $themes, $theme, array $expected) {
     // Mocks and stubs.
@@ -126,18 +128,45 @@ public function testGetBaseThemes(array $themes, $theme, array $expected) {
     $theme_engine_list = $this->prophesize(ThemeEngineExtensionList::class);
     $theme_listing = new ThemeExtensionList($this->root, 'theme', new NullBackend('test'), new InfoParser($this->root), $module_handler->reveal(), $state, $config_factory, $theme_engine_list->reveal(), 'test');
 
+    $this->expectDeprecation("\Drupal\Core\Extension\ThemeExtensionList::getBaseThemes() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. There is no direct replacement. See https://www.drupal.org/node/3413187");
     $base_themes = $theme_listing->getBaseThemes($themes, $theme);
 
     $this->assertEquals($expected, $base_themes);
   }
 
   /**
-   * Provides test data for testGetBaseThemes.
+   * Tests getting the base themes for a set of defined themes.
+   *
+   * @param array $themes
+   *   An array of available themes, keyed by the theme name.
+   * @param string $theme
+   *   The theme name to find all its base themes.
+   * @param array $expected
+   *   The expected base themes.
+   *
+   * @dataProvider providerTestDoGetBaseThemes
+   */
+  public function testDoGetBaseThemes(array $themes, $theme, array $expected): void {
+    // Mocks and stubs.
+    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
+    $state = new State(new KeyValueMemoryFactory());
+    $config_factory = $this->getConfigFactoryStub([]);
+    $theme_engine_list = $this->prophesize(ThemeEngineExtensionList::class);
+    $theme_listing = new ThemeExtensionList($this->root, 'theme', new NullBackend('test'), new InfoParser($this->root), $module_handler->reveal(), $state, $config_factory, $theme_engine_list->reveal(), 'test');
+
+    $method_to_test = (new \ReflectionObject($theme_listing))->getMethod('doGetBaseThemes');
+    $base_themes = $method_to_test->invoke($theme_listing, $themes, $theme);
+
+    $this->assertEquals($expected, $base_themes);
+  }
+
+  /**
+   * Provides test data for testDoGetBaseThemes.
    *
    * @return array
    *   An array of theme test data.
    */
-  public static function providerTestGetBaseThemes() {
+  public static function providerTestDoGetBaseThemes() {
     $data = [];
 
     // Tests a theme without any base theme.
-- 
GitLab