Issue #3285131 by andregp, daffie, catch, longwave: Fix constructor deprecation in Drupal\Core\Theme\Registry::__construct()

merge-requests/3695/head
catch 2022-06-17 14:22:33 +01:00
parent 70d480ab7f
commit 355a1a6887
6 changed files with 22 additions and 14 deletions

View File

@ -1416,7 +1416,7 @@ services:
arguments: ['%app.root%', '@theme_handler', '@cache.bootstrap', '@module_handler']
theme.registry:
class: Drupal\Core\Theme\Registry
arguments: ['%app.root%', '@cache.default', '@lock', '@module_handler', '@theme_handler', '@theme.initialization', null, '@cache.bootstrap', '@extension.list.module']
arguments: ['%app.root%', '@cache.default', '@lock', '@module_handler', '@theme_handler', '@theme.initialization', '@cache.bootstrap', '@extension.list.module']
tags:
- { name: needs_destruction }
calls:

View File

@ -174,19 +174,18 @@ class Registry implements DestructableInterface {
* The theme handler.
* @param \Drupal\Core\Theme\ThemeInitializationInterface $theme_initialization
* The theme initialization.
* @param string $theme_name
* (optional) The name of the theme for which to construct the registry.
* @param \Drupal\Core\Cache\CacheBackendInterface $runtime_cache
* The cache backend interface to use for the runtime theme registry data.
* @param \Drupal\Core\Extension\ModuleExtensionList $module_list
* The module list.
* @param string $theme_name
* (optional) The name of the theme for which to construct the registry.
*/
public function __construct($root, CacheBackendInterface $cache, LockBackendInterface $lock, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, ThemeInitializationInterface $theme_initialization, $theme_name = NULL, CacheBackendInterface $runtime_cache = NULL, ModuleExtensionList $module_list = NULL) {
public function __construct($root, CacheBackendInterface $cache, LockBackendInterface $lock, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, ThemeInitializationInterface $theme_initialization, CacheBackendInterface $runtime_cache, ModuleExtensionList $module_list, $theme_name = NULL) {
$this->root = $root;
$this->cache = $cache;
$this->lock = $lock;
$this->moduleHandler = $module_handler;
$this->themeName = $theme_name;
$this->themeHandler = $theme_handler;
$this->themeInitialization = $theme_initialization;
$this->runtimeCache = $runtime_cache;
@ -195,6 +194,7 @@ class Registry implements DestructableInterface {
$module_list = \Drupal::service('extension.list.module');
}
$this->moduleList = $module_list;
$this->themeName = $theme_name;
}
/**

View File

@ -74,11 +74,11 @@ class RegistryTest extends KernelTestBase {
$module_list = $this->container->get('extension.list.module');
assert($module_list instanceof ModuleExtensionList);
$registry_subsub_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_subsubtheme', NULL, $module_list);
$registry_subsub_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap'), $module_list, 'test_subsubtheme');
$registry_subsub_theme->setThemeManager(\Drupal::theme());
$registry_sub_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_subtheme', NULL, $module_list);
$registry_sub_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap'), $module_list, 'test_subtheme');
$registry_sub_theme->setThemeManager(\Drupal::theme());
$registry_base_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_basetheme', NULL, $module_list);
$registry_base_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap'), $module_list, 'test_basetheme');
$registry_base_theme->setThemeManager(\Drupal::theme());
$preprocess_functions = $registry_subsub_theme->get()['theme_test_template_test']['preprocess functions'];
@ -112,7 +112,7 @@ class RegistryTest extends KernelTestBase {
$extension_list = $this->container->get('extension.list.module');
assert($extension_list instanceof ModuleExtensionList);
$registry_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme', NULL, $extension_list);
$registry_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap'), $extension_list, 'test_theme');
$registry_theme->setThemeManager(\Drupal::theme());
$suggestions = ['__kitten', '__flamingo'];
@ -154,7 +154,7 @@ class RegistryTest extends KernelTestBase {
$extension_list = $this->container->get('extension.list.module');
assert($extension_list instanceof ModuleExtensionList);
$registry = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme', NULL, $extension_list);
$registry = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap'), $extension_list, 'test_theme');
$registry->setThemeManager(\Drupal::theme());
$this->assertEquals('value', $registry->get()['theme_test_template_test']['variables']['additional']);
}
@ -244,7 +244,7 @@ class RegistryTest extends KernelTestBase {
$extension_list = \Drupal::service('extension.list.module');
assert($extension_list instanceof ModuleExtensionList);
$registry_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme', NULL, $extension_list);
$registry_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap'), $extension_list, 'test_theme');
$registry_theme->setThemeManager(\Drupal::theme());
$expected = [

View File

@ -87,7 +87,7 @@ class Stable9TemplateOverrideTest extends KernelTestBase {
* Ensures that Stable 9 overrides all relevant core templates.
*/
public function testStable9TemplateOverrides() {
$registry = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $this->themeHandler, \Drupal::service('theme.initialization'), 'stable9', NULL, \Drupal::service('extension.list.module'));
$registry = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $this->themeHandler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap'), \Drupal::service('extension.list.module'), 'stable9');
$registry->setThemeManager(\Drupal::theme());
$registry_full = $registry->get();

View File

@ -85,7 +85,7 @@ class StableTemplateOverrideTest extends KernelTestBase {
* Ensures that Stable overrides all relevant core templates.
*/
public function testStableTemplateOverrides() {
$registry = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $this->themeHandler, \Drupal::service('theme.initialization'), 'stable', NULL, \Drupal::service('extension.list.module'));
$registry = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $this->themeHandler, \Drupal::service('theme.initialization'), \Drupal::service('cache.bootstrap'), \Drupal::service('extension.list.module'), 'stable');
$registry->setThemeManager(\Drupal::theme());
$registry_full = $registry->get();

View File

@ -55,6 +55,13 @@ class RegistryTest extends UnitTestCase {
*/
protected $themeInitialization;
/**
* The mocked cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $runtimeCache;
/**
* The theme manager.
*
@ -87,9 +94,10 @@ class RegistryTest extends UnitTestCase {
$this->moduleHandler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface');
$this->themeHandler = $this->createMock('Drupal\Core\Extension\ThemeHandlerInterface');
$this->themeInitialization = $this->createMock('Drupal\Core\Theme\ThemeInitializationInterface');
$this->runtimeCache = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
$this->themeManager = $this->createMock('Drupal\Core\Theme\ThemeManagerInterface');
$this->moduleList = $this->createMock(ModuleExtensionList::class);
$this->registry = new Registry($this->root, $this->cache, $this->lock, $this->moduleHandler, $this->themeHandler, $this->themeInitialization, NULL, NULL, $this->moduleList);
$this->registry = new Registry($this->root, $this->cache, $this->lock, $this->moduleHandler, $this->themeHandler, $this->themeInitialization, $this->runtimeCache, $this->moduleList);
$this->registry->setThemeManager($this->themeManager);
}