From d8435a0695b12869b25a82f637cad207f82ceaa8 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Tue, 14 Jun 2022 11:10:54 +0100 Subject: [PATCH] Issue #3285503 by quietone, longwave: Remove deprecated code in constructors --- .../EntityLastInstalledSchemaRepository.php | 6 +-- .../Drupal/Core/TempStore/SharedTempStore.php | 11 +---- .../Core/TempStore/SharedTempStoreFactory.php | 11 +---- .../Drupal/Core/Template/TwigExtension.php | 6 +-- .../ckeditor/src/Plugin/Editor/CKEditor.php | 10 +--- .../BaseFieldFileFormatterBase.php | 6 +-- .../file/src/Plugin/views/field/File.php | 6 +-- .../Core/TempStore/SharedTempStoreTest.php | 49 ------------------- 8 files changed, 7 insertions(+), 98 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/EntityLastInstalledSchemaRepository.php b/core/lib/Drupal/Core/Entity/EntityLastInstalledSchemaRepository.php index aed6a48de651..1b3c096126ce 100644 --- a/core/lib/Drupal/Core/Entity/EntityLastInstalledSchemaRepository.php +++ b/core/lib/Drupal/Core/Entity/EntityLastInstalledSchemaRepository.php @@ -41,12 +41,8 @@ class EntityLastInstalledSchemaRepository implements EntityLastInstalledSchemaRe * @param \Drupal\Core\Cache\CacheBackendInterface $cache * The cache backend. */ - public function __construct(KeyValueFactoryInterface $key_value_factory, CacheBackendInterface $cache = NULL) { + public function __construct(KeyValueFactoryInterface $key_value_factory, CacheBackendInterface $cache) { $this->keyValueFactory = $key_value_factory; - if (!$cache) { - @trigger_error('The cache.discovery service must be passed to EntityLastInstalledSchemaRepository::__construct(), it is required before drupal:10.0.0.', E_USER_DEPRECATED); - $cache = \Drupal::cache('discovery'); - } $this->cacheBackend = $cache; } diff --git a/core/lib/Drupal/Core/TempStore/SharedTempStore.php b/core/lib/Drupal/Core/TempStore/SharedTempStore.php index 75ec79a3ae39..089941c8de04 100644 --- a/core/lib/Drupal/Core/TempStore/SharedTempStore.php +++ b/core/lib/Drupal/Core/TempStore/SharedTempStore.php @@ -103,20 +103,11 @@ class SharedTempStore { * @param int $expire * The time to live for items, in seconds. */ - public function __construct(KeyValueStoreExpirableInterface $storage, LockBackendInterface $lock_backend, $owner, RequestStack $request_stack, $current_user = NULL, $expire = 604800) { + public function __construct(KeyValueStoreExpirableInterface $storage, LockBackendInterface $lock_backend, $owner, RequestStack $request_stack, AccountProxyInterface $current_user, $expire = 604800) { $this->storage = $storage; $this->lockBackend = $lock_backend; $this->owner = $owner; $this->requestStack = $request_stack; - if (!$current_user instanceof AccountProxyInterface) { - @trigger_error('Calling ' . __METHOD__ . '() without the $current_user argument is deprecated in drupal:9.2.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3006268', E_USER_DEPRECATED); - if (is_int($current_user)) { - // If the $current_user argument is numeric then this object has been - // instantiated with the old constructor signature. - $expire = $current_user; - } - $current_user = \Drupal::currentUser(); - } $this->currentUser = $current_user; $this->expire = $expire; } diff --git a/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php b/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php index 3972940ddceb..c206585f6acb 100644 --- a/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php +++ b/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php @@ -62,19 +62,10 @@ class SharedTempStoreFactory { * @param int $expire * The time to live for items, in seconds. */ - public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, RequestStack $request_stack, $current_user = NULL, $expire = 604800) { + public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, RequestStack $request_stack, AccountProxyInterface $current_user, $expire = 604800) { $this->storageFactory = $storage_factory; $this->lockBackend = $lock_backend; $this->requestStack = $request_stack; - if (!$current_user instanceof AccountProxyInterface) { - @trigger_error('Calling ' . __METHOD__ . '() without the $current_user argument is deprecated in drupal:9.2.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3006268', E_USER_DEPRECATED); - if (is_int($current_user)) { - // If the $current_user argument is numeric then this object has been - // instantiated with the old constructor signature. - $expire = $current_user; - } - $current_user = \Drupal::currentUser(); - } $this->currentUser = $current_user; $this->expire = $expire; } diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php index 1a75a9a6ac92..ef62bbec5e4d 100644 --- a/core/lib/Drupal/Core/Template/TwigExtension.php +++ b/core/lib/Drupal/Core/Template/TwigExtension.php @@ -83,15 +83,11 @@ class TwigExtension extends AbstractExtension { * @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator * The file URL generator. */ - public function __construct(RendererInterface $renderer, UrlGeneratorInterface $url_generator, ThemeManagerInterface $theme_manager, DateFormatterInterface $date_formatter, FileUrlGeneratorInterface $file_url_generator = NULL) { + public function __construct(RendererInterface $renderer, UrlGeneratorInterface $url_generator, ThemeManagerInterface $theme_manager, DateFormatterInterface $date_formatter, FileUrlGeneratorInterface $file_url_generator) { $this->renderer = $renderer; $this->urlGenerator = $url_generator; $this->themeManager = $theme_manager; $this->dateFormatter = $date_formatter; - if (!$file_url_generator) { - @trigger_error('Calling TwigExtension::__construct() without the $file_url_generator argument is deprecated in drupal:9.3.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/2940031.', E_USER_DEPRECATED); - $file_url_generator = \Drupal::service('file_url_generator'); - } $this->fileUrlGenerator = $file_url_generator; } diff --git a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php index 923bf91f9bbe..9d36a8e9667c 100644 --- a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php +++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php @@ -105,22 +105,14 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface { * @param \Drupal\Core\Extension\ModuleExtensionList $module_list * The module list service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer, StateInterface $state, FileUrlGeneratorInterface $file_url_generator = NULL, ModuleExtensionList $module_list = NULL) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer, StateInterface $state, FileUrlGeneratorInterface $file_url_generator, ModuleExtensionList $module_list) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->ckeditorPluginManager = $ckeditor_plugin_manager; $this->moduleHandler = $module_handler; $this->languageManager = $language_manager; $this->renderer = $renderer; $this->state = $state; - if (!$file_url_generator) { - @trigger_error('Calling CKEditor::__construct() without the $file_url_generator argument is deprecated in drupal:9.3.0 and will be required before drupal:10.0.0. See https://www.drupal.org/node/2940031', E_USER_DEPRECATED); - $file_url_generator = \Drupal::service('file_url_generator'); - } $this->fileUrlGenerator = $file_url_generator; - if (!$module_list) { - @trigger_error('Calling CKEditor::__construct() without the $module_list argument is deprecated in drupal:9.3.0 and is required in drupal:10.0.0. See https://www.drupal.org/node/2940438', E_USER_DEPRECATED); - $module_list = \Drupal::service('extension.list.module'); - } $this->moduleList = $module_list; } diff --git a/core/modules/file/src/Plugin/Field/FieldFormatter/BaseFieldFileFormatterBase.php b/core/modules/file/src/Plugin/Field/FieldFormatter/BaseFieldFileFormatterBase.php index f193d4590890..e373dfbf2013 100644 --- a/core/modules/file/src/Plugin/Field/FieldFormatter/BaseFieldFileFormatterBase.php +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/BaseFieldFileFormatterBase.php @@ -42,12 +42,8 @@ abstract class BaseFieldFileFormatterBase extends FormatterBase { * @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator * The file URL generator. */ - public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, FileUrlGeneratorInterface $file_url_generator = NULL) { + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, FileUrlGeneratorInterface $file_url_generator) { parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); - if (!$file_url_generator) { - @trigger_error('Calling BaseFieldFileFormatterBase::__construct() without the $file_url_generator argument is deprecated in drupal:9.3.0 and the $file_url_generator argument will be required in drupal:10.0.0. See https://www.drupal.org/node/2940031', E_USER_DEPRECATED); - $file_url_generator = \Drupal::service('file_url_generator'); - } $this->fileUrlGenerator = $file_url_generator; } diff --git a/core/modules/file/src/Plugin/views/field/File.php b/core/modules/file/src/Plugin/views/field/File.php index 6a7e1ed42191..e00d50d9cfa7 100644 --- a/core/modules/file/src/Plugin/views/field/File.php +++ b/core/modules/file/src/Plugin/views/field/File.php @@ -38,12 +38,8 @@ class File extends FieldPluginBase { * @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator * The file URL generator. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, FileUrlGeneratorInterface $file_url_generator = NULL) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, FileUrlGeneratorInterface $file_url_generator) { parent::__construct($configuration, $plugin_id, $plugin_definition); - if (!$file_url_generator) { - @trigger_error('Calling File::__construct() without the $file_url_generator argument is deprecated in drupal:9.3.0 and the $file_url_generator argument will be required in drupal:10.0.0. See https://www.drupal.org/node/2940031', E_USER_DEPRECATED); - $file_url_generator = \Drupal::service('file_url_generator'); - } $this->fileUrlGenerator = $file_url_generator; } diff --git a/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php b/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php index 75e7119209ba..e65c644afba5 100644 --- a/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php +++ b/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php @@ -2,11 +2,8 @@ namespace Drupal\Tests\Core\TempStore; -use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\TempStore\Lock; -use Drupal\Core\TempStore\SharedTempStoreFactory; use Drupal\Tests\UnitTestCase; use Drupal\Core\TempStore\SharedTempStore; use Drupal\Core\TempStore\TempStoreException; @@ -377,52 +374,6 @@ public function testSerialization() { $this->assertSame($unserializable_request, $request_stack->pop()); } - /** - * @group legacy - */ - public function testLegacyConstructor() { - $this->expectDeprecation('Calling Drupal\Core\TempStore\SharedTempStore::__construct() without the $current_user argument is deprecated in drupal:9.2.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3006268'); - - $container = new ContainerBuilder(); - $current_user = $this->createMock(AccountProxyInterface::class); - $container->set('current_user', $current_user); - \Drupal::setContainer($container); - $store = new SharedTempStore($this->keyValue, $this->lock, 2, $this->requestStack, 1000); - $reflection_class = new \ReflectionClass(SharedTempStore::class); - - $current_user_property = $reflection_class->getProperty('currentUser'); - $current_user_property->setAccessible(TRUE); - $this->assertSame($current_user, $current_user_property->getValue($store)); - - $expire_property = $reflection_class->getProperty('expire'); - $expire_property->setAccessible(TRUE); - $this->assertSame(1000, $expire_property->getValue($store)); - } - - /** - * @group legacy - * @covers \Drupal\Core\TempStore\SharedTempStoreFactory::__construct - */ - public function testLegacyFactoryConstructor() { - $this->expectDeprecation('Calling Drupal\Core\TempStore\SharedTempStoreFactory::__construct() without the $current_user argument is deprecated in drupal:9.2.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3006268'); - - $container = new ContainerBuilder(); - $current_user = $this->createMock(AccountProxyInterface::class); - $container->set('current_user', $current_user); - \Drupal::setContainer($container); - $key_value_factory = $this->prophesize(KeyValueExpirableFactoryInterface::class); - $store = new SharedTempStoreFactory($key_value_factory->reveal(), $this->lock, $this->requestStack, 1000); - $reflection_class = new \ReflectionClass(SharedTempStoreFactory::class); - - $current_user_property = $reflection_class->getProperty('currentUser'); - $current_user_property->setAccessible(TRUE); - $this->assertSame($current_user, $current_user_property->getValue($store)); - - $expire_property = $reflection_class->getProperty('expire'); - $expire_property->setAccessible(TRUE); - $this->assertSame(1000, $expire_property->getValue($store)); - } - } /** -- GitLab