Issue #2972153 by dimitriskr, alexpott, smustgrave, andypost, kostyashupenko: Deprecate ThemeHandlerInterface::getBaseThemes and remove usages from core

merge-requests/7062/head
Dave Long 2024-03-15 17:56:10 +00:00
parent 0e6acad498
commit 1e80a22b06
No known key found for this signature in database
GPG Key ID: ED52AE211E142771
4 changed files with 44 additions and 3 deletions

View File

@ -210,8 +210,14 @@ class ThemeExtensionList extends ExtensionList {
* @return array * @return array
* Returns an array of all of the theme's ancestors; the first element's * Returns an array of all of the theme's ancestors; the first element's
* value will be NULL if an error occurred. * 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) { 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); return $this->doGetBaseThemes($themes, $theme);
} }

View File

@ -133,6 +133,7 @@ class ThemeHandler implements ThemeHandlerInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getBaseThemes(array $themes, $theme) { 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); return $this->themeList->getBaseThemes($themes, $theme);
} }

View File

@ -98,6 +98,11 @@ interface ThemeHandlerInterface {
* @return array * @return array
* Returns an array of all of the theme's ancestors; the first element's * Returns an array of all of the theme's ancestors; the first element's
* value will be NULL if an error occurred. * 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); public function getBaseThemes(array $themes, $theme);

View File

@ -116,7 +116,9 @@ class ThemeExtensionListTest extends UnitTestCase {
* @param array $expected * @param array $expected
* The expected base themes. * The expected base themes.
* *
* @dataProvider providerTestGetBaseThemes * @dataProvider providerTestDoGetBaseThemes
*
* @group legacy
*/ */
public function testGetBaseThemes(array $themes, $theme, array $expected) { public function testGetBaseThemes(array $themes, $theme, array $expected) {
// Mocks and stubs. // Mocks and stubs.
@ -126,18 +128,45 @@ class ThemeExtensionListTest extends UnitTestCase {
$theme_engine_list = $this->prophesize(ThemeEngineExtensionList::class); $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'); $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); $base_themes = $theme_listing->getBaseThemes($themes, $theme);
$this->assertEquals($expected, $base_themes); $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 * @return array
* An array of theme test data. * An array of theme test data.
*/ */
public static function providerTestGetBaseThemes() { public static function providerTestDoGetBaseThemes() {
$data = []; $data = [];
// Tests a theme without any base theme. // Tests a theme without any base theme.