From dcc51c80a2ee2a26dd39732b9eef4c6c7df1ffeb Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Tue, 15 Mar 2022 12:47:59 +0000 Subject: [PATCH] Issue #3261248 by paulocs, andregp, andypost, longwave, quietone: Remove deprecated user.module functions --- .../MaintenanceModeSubscriber.php | 6 +- core/lib/Drupal/Core/Site/MaintenanceMode.php | 6 +- .../src/Authentication/Provider/Cookie.php | 8 +- .../UserAuthenticationController.php | 6 +- core/modules/user/src/Entity/Role.php | 2 +- .../MaintenanceModeSubscriber.php | 28 ------ core/modules/user/src/Form/UserLoginForm.php | 6 +- .../user/src/Form/UserPasswordForm.php | 10 +- .../PasswordWidgetThemeFunctionTest.php | 70 -------------- .../Condition/UserRoleConditionTest.php | 10 -- .../UserAuthenticationControllerTest.php | 52 ----------- .../src/Kernel/Form/UserLoginFormTest.php | 44 --------- .../user/tests/src/Kernel/UserLegacyTest.php | 25 ----- .../tests/src/Kernel/UserMailNotifyTest.php | 11 --- .../tests/src/Kernel/UserRoleEntityTest.php | 9 +- .../js/password-theme-functions.es6.js | 91 ------------------- .../js/password-theme-functions.js | 47 ---------- .../password_theme_function_test.info.yml | 7 -- ...password_theme_function_test.libraries.yml | 6 -- core/modules/user/user.es6.js | 45 ++------- core/modules/user/user.js | 43 ++------- core/modules/user/user.module | 32 +------ 22 files changed, 28 insertions(+), 536 deletions(-) delete mode 100644 core/modules/user/tests/src/FunctionalJavascript/PasswordWidgetThemeFunctionTest.php delete mode 100644 core/modules/user/tests/src/Kernel/Controller/UserAuthenticationControllerTest.php delete mode 100644 core/modules/user/tests/src/Kernel/Form/UserLoginFormTest.php delete mode 100644 core/modules/user/tests/src/Kernel/UserLegacyTest.php delete mode 100644 core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.es6.js delete mode 100644 core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.js delete mode 100644 core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.info.yml delete mode 100644 core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.libraries.yml diff --git a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php index ee2129d7fced..172fd1425c9b 100644 --- a/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php @@ -94,7 +94,7 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface { * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $event_dispatcher * The event dispatcher. */ - public function __construct(MaintenanceModeInterface $maintenance_mode, ConfigFactoryInterface $config_factory, TranslationInterface $translation, UrlGeneratorInterface $url_generator, AccountInterface $account, BareHtmlPageRendererInterface $bare_html_page_renderer, MessengerInterface $messenger, EventDispatcherInterface $event_dispatcher = NULL) { + public function __construct(MaintenanceModeInterface $maintenance_mode, ConfigFactoryInterface $config_factory, TranslationInterface $translation, UrlGeneratorInterface $url_generator, AccountInterface $account, BareHtmlPageRendererInterface $bare_html_page_renderer, MessengerInterface $messenger, EventDispatcherInterface $event_dispatcher) { $this->maintenanceMode = $maintenance_mode; $this->config = $config_factory; $this->stringTranslation = $translation; @@ -102,10 +102,6 @@ public function __construct(MaintenanceModeInterface $maintenance_mode, ConfigFa $this->account = $account; $this->bareHtmlPageRenderer = $bare_html_page_renderer; $this->messenger = $messenger; - if (!$event_dispatcher) { - @trigger_error('Calling MaintenanceModeSubscriber::__construct() without the $event_dispatcher argument is deprecated in drupal:9.4.0 and the $event_dispatcher argument will be required in drupal:10.0.0. See https://www.drupal.org/node/3255799', E_USER_DEPRECATED); - $event_dispatcher = \Drupal::service('event_dispatcher'); - } $this->eventDispatcher = $event_dispatcher; } diff --git a/core/lib/Drupal/Core/Site/MaintenanceMode.php b/core/lib/Drupal/Core/Site/MaintenanceMode.php index 1713d6346c57..65b74061f680 100644 --- a/core/lib/Drupal/Core/Site/MaintenanceMode.php +++ b/core/lib/Drupal/Core/Site/MaintenanceMode.php @@ -35,12 +35,8 @@ class MaintenanceMode implements MaintenanceModeInterface { * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. */ - public function __construct(StateInterface $state, ConfigFactoryInterface $config_factory = NULL) { + public function __construct(StateInterface $state, ConfigFactoryInterface $config_factory) { $this->state = $state; - if (!$config_factory) { - @trigger_error('Calling MaintenanceMode::__construct() without the $config_factory argument is deprecated in drupal:9.4.0 and the $config_factory argument will be required in drupal:10.0.0. See https://www.drupal.org/node/3255815', E_USER_DEPRECATED); - $config_factory = \Drupal::service('config.factory'); - } $this->config = $config_factory; } diff --git a/core/modules/user/src/Authentication/Provider/Cookie.php b/core/modules/user/src/Authentication/Provider/Cookie.php index 20c2719a25a3..9cae48471bac 100644 --- a/core/modules/user/src/Authentication/Provider/Cookie.php +++ b/core/modules/user/src/Authentication/Provider/Cookie.php @@ -53,17 +53,13 @@ class Cookie implements AuthenticationProviderInterface, EventSubscriberInterfac * The session configuration. * @param \Drupal\Core\Database\Connection $connection * The database connection. - * @param \Drupal\Core\Messenger\MessengerInterface|null $messenger + * @param \Drupal\Core\Messenger\MessengerInterface $messenger * The messenger. */ - public function __construct(SessionConfigurationInterface $session_configuration, Connection $connection, MessengerInterface $messenger = NULL) { + public function __construct(SessionConfigurationInterface $session_configuration, Connection $connection, MessengerInterface $messenger) { $this->sessionConfiguration = $session_configuration; $this->connection = $connection; $this->messenger = $messenger; - if ($this->messenger === NULL) { - @trigger_error('The MessengerInterface must be passed to ' . __NAMESPACE__ . '\Cookie::__construct(). It was added in drupal:9.2.0 and will be required before drupal:10.0.0.', E_USER_DEPRECATED); - $this->messenger = \Drupal::messenger(); - } } /** diff --git a/core/modules/user/src/Controller/UserAuthenticationController.php b/core/modules/user/src/Controller/UserAuthenticationController.php index ec36f9fd6419..718adb1e83ed 100644 --- a/core/modules/user/src/Controller/UserAuthenticationController.php +++ b/core/modules/user/src/Controller/UserAuthenticationController.php @@ -114,11 +114,7 @@ class UserAuthenticationController extends ControllerBase implements ContainerIn * @param \Psr\Log\LoggerInterface $logger * A logger instance. */ - public function __construct($user_flood_control, UserStorageInterface $user_storage, CsrfTokenGenerator $csrf_token, UserAuthInterface $user_auth, RouteProviderInterface $route_provider, Serializer $serializer, array $serializer_formats, LoggerInterface $logger) { - if (!$user_flood_control instanceof UserFloodControlInterface) { - @trigger_error('Passing the flood service to ' . __METHOD__ . ' is deprecated in drupal:9.1.0 and is replaced by user.flood_control in drupal:10.0.0. See https://www.drupal.org/node/3067148', E_USER_DEPRECATED); - $user_flood_control = \Drupal::service('user.flood_control'); - } + public function __construct(UserFloodControlInterface $user_flood_control, UserStorageInterface $user_storage, CsrfTokenGenerator $csrf_token, UserAuthInterface $user_auth, RouteProviderInterface $route_provider, Serializer $serializer, array $serializer_formats, LoggerInterface $logger) { $this->userFloodControl = $user_flood_control; $this->userStorage = $user_storage; $this->csrfToken = $csrf_token; diff --git a/core/modules/user/src/Entity/Role.php b/core/modules/user/src/Entity/Role.php index 97b015571943..f65af5108854 100644 --- a/core/modules/user/src/Entity/Role.php +++ b/core/modules/user/src/Entity/Role.php @@ -203,7 +203,7 @@ public function calculateDependencies() { $valid_permissions = array_intersect($this->permissions, array_keys($permission_definitions)); $invalid_permissions = array_diff($this->permissions, $valid_permissions); if (!empty($invalid_permissions) && !$this->get('skip_missing_permission_deprecation')) { - @trigger_error('Adding non-existent permissions to a role is deprecated in drupal:9.3.0 and triggers a runtime exception before drupal:10.0.0. The incorrect permissions are "' . implode('", "', $invalid_permissions) . '". Permissions should be defined in a permissions.yml file or a permission callback. See https://www.drupal.org/node/3193348', E_USER_DEPRECATED); + throw new \RuntimeException('Adding non-existent permissions to a role is not allowed. The incorrect permissions are "' . implode('", "', $invalid_permissions) . '".'); } foreach ($valid_permissions as $permission) { // Depend on the module that is providing this permissions. diff --git a/core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php b/core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php index 390dc182cd62..a5c29b153c7c 100644 --- a/core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php +++ b/core/modules/user/src/EventSubscriber/MaintenanceModeSubscriber.php @@ -2,7 +2,6 @@ namespace Drupal\user\EventSubscriber; -use Drupal\Core\Routing\RouteMatch; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Site\MaintenanceModeEvents; use Drupal\Core\Site\MaintenanceModeInterface; @@ -43,33 +42,6 @@ public function __construct(MaintenanceModeInterface $maintenance_mode, AccountI $this->account = $account; } - /** - * Logout users if site is in maintenance mode. - * - * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event - * The event to process. - * - * @deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use - * \Drupal\user\EventSubscriber::onMaintenanceModeRequest() instead. - * - * @see https://www.drupal.org/node/3255799 - */ - public function onKernelRequestMaintenance(RequestEvent $event) { - @trigger_error('\Drupal\user\EventSubscriber::onKernelRequestMaintenance() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use \Drupal\user\EventSubscriber::onMaintenanceModeRequest() instead. See https://www.drupal.org/node/3255799', E_USER_DEPRECATED); - $request = $event->getRequest(); - $route_match = RouteMatch::createFromRequest($request); - if ($this->maintenanceMode->applies($route_match)) { - // If the site is offline, log out unprivileged users. - if ($this->account->isAuthenticated() && !$this->maintenanceMode->exempt($this->account)) { - user_logout(); - // Redirect to homepage. - $event->setResponse( - new RedirectResponse(Url::fromRoute('<front>')->toString()) - ); - } - } - } - /** * Logout users if site is in maintenance mode and user is not exempt. * diff --git a/core/modules/user/src/Form/UserLoginForm.php b/core/modules/user/src/Form/UserLoginForm.php index 1fb58ddbde92..cde450c11222 100644 --- a/core/modules/user/src/Form/UserLoginForm.php +++ b/core/modules/user/src/Form/UserLoginForm.php @@ -69,11 +69,7 @@ class UserLoginForm extends FormBase { * @param \Drupal\Core\Render\BareHtmlPageRendererInterface $bare_html_renderer * The renderer. */ - public function __construct($user_flood_control, UserStorageInterface $user_storage, UserAuthInterface $user_auth, RendererInterface $renderer, BareHtmlPageRendererInterface $bare_html_renderer) { - if (!$user_flood_control instanceof UserFloodControlInterface) { - @trigger_error('Passing the flood service to ' . __METHOD__ . ' is deprecated in drupal:9.1.0 and is replaced by user.flood_control in drupal:10.0.0. See https://www.drupal.org/node/3067148', E_USER_DEPRECATED); - $user_flood_control = \Drupal::service('user.flood_control'); - } + public function __construct(UserFloodControlInterface $user_flood_control, UserStorageInterface $user_storage, UserAuthInterface $user_auth, RendererInterface $renderer, BareHtmlPageRendererInterface $bare_html_renderer) { $this->userFloodControl = $user_flood_control; $this->userStorage = $user_storage; $this->userAuth = $user_auth; diff --git a/core/modules/user/src/Form/UserPasswordForm.php b/core/modules/user/src/Form/UserPasswordForm.php index a8fc6db82f06..9a950972bc87 100644 --- a/core/modules/user/src/Form/UserPasswordForm.php +++ b/core/modules/user/src/Form/UserPasswordForm.php @@ -75,20 +75,12 @@ class UserPasswordForm extends FormBase { * @param \Drupal\Component\Utility\EmailValidatorInterface $email_validator * The email validator service. */ - public function __construct(UserStorageInterface $user_storage, LanguageManagerInterface $language_manager, ConfigFactory $config_factory, FloodInterface $flood, TypedDataManagerInterface $typed_data_manager = NULL, EmailValidatorInterface $email_validator = NULL) { + public function __construct(UserStorageInterface $user_storage, LanguageManagerInterface $language_manager, ConfigFactory $config_factory, FloodInterface $flood, TypedDataManagerInterface $typed_data_manager, EmailValidatorInterface $email_validator) { $this->userStorage = $user_storage; $this->languageManager = $language_manager; $this->configFactory = $config_factory; $this->flood = $flood; - if (is_null($typed_data_manager)) { - @trigger_error('Calling ' . __METHOD__ . ' without the $typed_data_manager argument is deprecated in drupal:9.2.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3189310', E_USER_DEPRECATED); - $typed_data_manager = \Drupal::typedDataManager(); - } $this->typedDataManager = $typed_data_manager; - if (is_null($email_validator)) { - @trigger_error('Calling ' . __METHOD__ . ' without the $email_validator argument is deprecated in drupal:9.2.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3189310', E_USER_DEPRECATED); - $email_validator = \Drupal::service('email.validator'); - } $this->emailValidator = $email_validator; } diff --git a/core/modules/user/tests/src/FunctionalJavascript/PasswordWidgetThemeFunctionTest.php b/core/modules/user/tests/src/FunctionalJavascript/PasswordWidgetThemeFunctionTest.php deleted file mode 100644 index 0794c9e42398..000000000000 --- a/core/modules/user/tests/src/FunctionalJavascript/PasswordWidgetThemeFunctionTest.php +++ /dev/null @@ -1,70 +0,0 @@ -<?php - -namespace Drupal\Tests\user\FunctionalJavascript; - -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; - -/** - * Tests the JS components added to the PasswordConfirm render element. - * - * @group user - */ -class PasswordWidgetThemeFunctionTest extends WebDriverTestBase { - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'password_theme_function_test'; - - /** - * {@inheritdoc} - * - * @todo Remove this class property in https://www.drupal.org/node/3217947. - */ - protected $failOnJavascriptConsoleErrors = FALSE; - - /** - * {@inheritdoc} - */ - protected static $modules = ['user']; - - /** - * User for testing. - * - * @var \Drupal\user\UserInterface - */ - protected $testUser; - - /** - * {@inheritdoc} - */ - protected function setUp(): void { - parent::setUp(); - $this->assert = $this->assertSession(); - - // Create a user. - $this->testUser = $this->createUser(); - $this->drupalLogin($this->testUser); - } - - /** - * Tests password widget theme functions and its deprecations. - * - * @group legacy - */ - public function testPasswordConfirmWidgetJsComponents() { - $this->expectDeprecation('Javascript Deprecation: Returning <span> without data-drupal-selector="password-match-status-text" attribute is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3152101'); - $this->expectDeprecation('Javascript Deprecation: The js-password-strength__indicator class is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Replace js-password-strength__indicator with a data-drupal-selector="password-strength-indicator" attribute. See https://www.drupal.org/node/3152101'); - $this->expectDeprecation('Javascript Deprecation: The js-password-strength__text class is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Replace js-password-strength__text with a data-drupal-selector="password-strength-text" attribute. See https://www.drupal.org/node/3152101'); - $this->expectDeprecation('Javascript Deprecation: The message property is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. The markup should be constructed using messageTips property and Drupal.theme.passwordSuggestions. See https://www.drupal.org/node/3130352'); - $assert_session = $this->assertSession(); - - $this->drupalGet($this->testUser->toUrl('edit-form')); - - $this->assertNotNull($assert_session->waitForText('Overridden passwordStrength:')); - $assert_session->elementTextContains('css', '.password-strength__meter', 'Overridden passwordStrength:'); - $assert_session->elementTextContains('css', '.password-confirm-message', 'Overridden passwordConfirmMessage:'); - $this->getSession()->getPage()->fillField('pass[pass1]', 'a'); - $assert_session->elementTextContains('css', '.password-suggestions', 'Overridden passwordSuggestions:'); - } - -} diff --git a/core/modules/user/tests/src/Kernel/Condition/UserRoleConditionTest.php b/core/modules/user/tests/src/Kernel/Condition/UserRoleConditionTest.php index cc00ab67c1c9..df75a08a3d4b 100644 --- a/core/modules/user/tests/src/Kernel/Condition/UserRoleConditionTest.php +++ b/core/modules/user/tests/src/Kernel/Condition/UserRoleConditionTest.php @@ -150,14 +150,4 @@ public function testConditions() { $this->assertEquals(new FormattableMarkup('The user is a member of @roles', ['@roles' => $this->role->label()]), $condition->summary()); } - /** - * @group legacy - */ - public function testLegacy() { - $this->expectDeprecation('Passing context values to plugins via configuration is deprecated in drupal:9.1.0 and will be removed before drupal:10.0.0. Instead, call ::setContextValue() on the plugin itself. See https://www.drupal.org/node/3120980'); - // Test Constructor injection. - $condition = $this->manager->createInstance('user_role', ['roles' => [RoleInterface::AUTHENTICATED_ID => RoleInterface::AUTHENTICATED_ID], 'context' => ['user' => $this->authenticated]]); - $this->assertTrue($condition->execute(), 'Constructor injection of context and configuration working as anticipated.'); - } - } diff --git a/core/modules/user/tests/src/Kernel/Controller/UserAuthenticationControllerTest.php b/core/modules/user/tests/src/Kernel/Controller/UserAuthenticationControllerTest.php deleted file mode 100644 index bf862ca8c460..000000000000 --- a/core/modules/user/tests/src/Kernel/Controller/UserAuthenticationControllerTest.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php - -namespace Drupal\Tests\user\Kernel\Controller; - -use Drupal\Core\Access\CsrfTokenGenerator; -use Drupal\Core\Flood\FloodInterface; -use Drupal\Core\Routing\RouteProviderInterface; -use Drupal\KernelTests\KernelTestBase; -use Drupal\user\Controller\UserAuthenticationController; -use Drupal\user\UserAuthInterface; -use Drupal\user\UserStorageInterface; -use Psr\Log\LoggerInterface; -use Symfony\Component\Serializer\Serializer; - -/** - * @coversDefaultClass \Drupal\user\Controller\UserController - * @group user - */ -class UserAuthenticationControllerTest extends KernelTestBase { - - /** - * {@inheritdoc} - */ - protected static $modules = ['user']; - - /** - * @group legacy - */ - public function testConstructorDeprecations() { - $this->expectDeprecation('Passing the flood service to Drupal\user\Controller\UserAuthenticationController::__construct is deprecated in drupal:9.1.0 and is replaced by user.flood_control in drupal:10.0.0. See https://www.drupal.org/node/3067148'); - $flood = $this->prophesize(FloodInterface::class); - $user_storage = $this->prophesize(UserStorageInterface::class); - $csrf_token = $this->prophesize(CsrfTokenGenerator::class); - $user_auth = $this->prophesize(UserAuthInterface::class); - $route_provider = $this->prophesize(RouteProviderInterface::class); - $serializer = $this->prophesize(Serializer::class); - $serializer_formats = []; - $logger = $this->prophesize(LoggerInterface::class); - $controller = new UserAuthenticationController( - $flood->reveal(), - $user_storage->reveal(), - $csrf_token->reveal(), - $user_auth->reveal(), - $route_provider->reveal(), - $serializer->reveal(), - $serializer_formats, - $logger->reveal() - ); - $this->assertNotNull($controller); - } - -} diff --git a/core/modules/user/tests/src/Kernel/Form/UserLoginFormTest.php b/core/modules/user/tests/src/Kernel/Form/UserLoginFormTest.php deleted file mode 100644 index 103fea2d9e9a..000000000000 --- a/core/modules/user/tests/src/Kernel/Form/UserLoginFormTest.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php - -namespace Drupal\Tests\user\Kernel\Form; - -use Drupal\Core\Flood\FloodInterface; -use Drupal\Core\Render\RendererInterface; -use Drupal\Core\Render\BareHtmlPageRendererInterface; -use Drupal\KernelTests\KernelTestBase; -use Drupal\user\Form\UserLoginForm; -use Drupal\user\UserAuthInterface; -use Drupal\user\UserStorageInterface; - -/** - * @coversDefaultClass \Drupal\user\Form\UserLoginForm - * @group user - */ -class UserLoginFormTest extends KernelTestBase { - - /** - * {@inheritdoc} - */ - protected static $modules = ['user']; - - /** - * @group legacy - */ - public function testConstructorDeprecations() { - $this->expectDeprecation('Passing the flood service to Drupal\user\Form\UserLoginForm::__construct is deprecated in drupal:9.1.0 and is replaced by user.flood_control in drupal:10.0.0. See https://www.drupal.org/node/3067148'); - $flood = $this->prophesize(FloodInterface::class); - $user_storage = $this->prophesize(UserStorageInterface::class); - $user_auth = $this->prophesize(UserAuthInterface::class); - $renderer = $this->prophesize(RendererInterface::class); - $bare_html_renderer = $this->prophesize(BareHtmlPageRendererInterface::class); - $form = new UserLoginForm( - $flood->reveal(), - $user_storage->reveal(), - $user_auth->reveal(), - $renderer->reveal(), - $bare_html_renderer->reveal() - ); - $this->assertNotNull($form); - } - -} diff --git a/core/modules/user/tests/src/Kernel/UserLegacyTest.php b/core/modules/user/tests/src/Kernel/UserLegacyTest.php deleted file mode 100644 index c65726a0004e..000000000000 --- a/core/modules/user/tests/src/Kernel/UserLegacyTest.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -namespace Drupal\Tests\user\Kernel; - -use Drupal\KernelTests\KernelTestBase; - -/** - * Tests legacy user functionality. - * - * @group user - * @group legacy - */ -class UserLegacyTest extends KernelTestBase { - - /** - * {@inheritdoc} - */ - protected static $modules = ['user']; - - public function testUserPassword() { - $this->expectDeprecation('user_password() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Password\PasswordGeneratorInterface::generate() instead. See https://www.drupal.org/node/3153113'); - $this->assertNotEmpty(user_password()); - } - -} diff --git a/core/modules/user/tests/src/Kernel/UserMailNotifyTest.php b/core/modules/user/tests/src/Kernel/UserMailNotifyTest.php index 2038d18c0ec0..813f26d16a7e 100644 --- a/core/modules/user/tests/src/Kernel/UserMailNotifyTest.php +++ b/core/modules/user/tests/src/Kernel/UserMailNotifyTest.php @@ -107,17 +107,6 @@ public function testUserMailsNotSent($op) { $this->assertEmpty($this->getMails()); } - /** - * Tests the deprecated $langcode argument to _user_mail_notify(). - * - * @group legacy - */ - public function testUserMailNotifyLangcodeDeprecation() { - $account = $this->createUser(); - $this->expectDeprecation('Specifying the notification language using the $langcode parameter is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Omit the parameter. See https://www.drupal.org/node/3187082'); - _user_mail_notify('password_reset', $account, $account->getPreferredLangcode()); - } - /** * Tests recovery email content and token langcode is aligned. */ diff --git a/core/modules/user/tests/src/Kernel/UserRoleEntityTest.php b/core/modules/user/tests/src/Kernel/UserRoleEntityTest.php index 5d85147ca13b..492fdac20fae 100644 --- a/core/modules/user/tests/src/Kernel/UserRoleEntityTest.php +++ b/core/modules/user/tests/src/Kernel/UserRoleEntityTest.php @@ -28,19 +28,18 @@ public function testOrderOfPermissions() { $this->assertEquals(['a', 'b', 'c'], $role->getPermissions()); } - /** - * @group legacy - */ public function testGrantingNonExistentPermission() { $role = Role::create(['id' => 'test_role', 'label' => 'Test role']); // A single permission that does not exist. - $this->expectDeprecation('Adding non-existent permissions to a role is deprecated in drupal:9.3.0 and triggers a runtime exception before drupal:10.0.0. The incorrect permissions are "does not exist". Permissions should be defined in a permissions.yml file or a permission callback. See https://www.drupal.org/node/3193348'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Adding non-existent permissions to a role is not allowed. The incorrect permissions are "does not exist".'); $role->grantPermission('does not exist') ->save(); // A multiple permissions that do not exist. - $this->expectDeprecation('Adding non-existent permissions to a role is deprecated in drupal:9.3.0 and triggers a runtime exception before drupal:10.0.0. The incorrect permissions are "does not exist", "also does not exist". Permissions should be defined in a permissions.yml file or a permission callback. See https://www.drupal.org/node/3193348'); + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Adding non-existent permissions to a role is not allowed. The incorrect permissions are "does not exist, also does not exist".'); $role->grantPermission('does not exist') ->grantPermission('also does not exist') ->save(); diff --git a/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.es6.js b/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.es6.js deleted file mode 100644 index 7d25a670a1a8..000000000000 --- a/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.es6.js +++ /dev/null @@ -1,91 +0,0 @@ -/** - * @file - * Overrides password theme functions for testing. - */ - -((Drupal) => { - /** - * Constructs a password strength message. - * - * @param {object} passwordSettings - * An object containing password related settings and translated text to - * display. - * @param {string} passwordSettings.strengthTitle - * The title that precedes the strength text. - * - * @return {string} - * Markup for password strength message. - */ - Drupal.theme.passwordStrength = ({ strengthTitle }) => { - const strengthIndicator = - '<span>Overridden passwordStrength:</span><div class="password-strength__indicator js-password-strength__indicator the-prior-class-is-deprecated" data-drupal-selector="a-distinct-absence-of-password-strength-indicator"></div>'; - const strengthText = - '<span class="password-strength__text js-password-strength__text the-prior-class-is-deprecated" data-drupal-selector="a-distinct-absence-of-password-strength-text"></span>'; - return ` - <div class="password-strength"> - <div class="password-strength__meter" data-drupal-selector="password-strength-meter">${strengthIndicator}</div> - <div aria-live="polite" aria-atomic="true" class="password-strength__title">${strengthTitle} ${strengthText}</div> - </div> - `; - }; - - /** - * Constructs password suggestions tips. - * - * @param {object} passwordSettings - * An object containing password related settings and translated text to - * display. - * @param {string} passwordSettings.hasWeaknesses - * The title that precedes tips. - * @param {Array.<string>} tips - * Array containing the tips. - * - * @return {string} - * Markup for password suggestions. - */ - Drupal.theme.passwordSuggestions = ({ hasWeaknesses }, tips) => - `<div class="password-suggestions">Overridden passwordSuggestions: ${ - tips.length - ? `${hasWeaknesses}<ul><li>${tips.join('</li><li>')}</li></ul>` - : '' - }</div>`; - - /** - * Constructs a password confirm message element. - * - * @param {object} passwordSettings - * An object containing password related settings and translated text to - * display. - * @param {string} passwordSettings.confirmTitle - * The translated confirm description that labels the actual confirm text. - * - * @return {string} - * Markup for the password confirm message. - */ - Drupal.theme.passwordConfirmMessage = ({ confirmTitle }) => { - const confirmTextWrapper = - '<span>Overridden passwordConfirmMessage:</span><span data-drupal-selector="a-distinct-absence-of-password-match-status-text"></span>'; - return `<div aria-live="polite" aria-atomic="true" class="password-confirm-message" data-drupal-selector="password-confirm-message">${confirmTitle} ${confirmTextWrapper}</div>`; - }; - - /** - * Confirm deprecation of property in evaluatePasswordStrength() return. - * - * @type {Drupal~behavior} - * - * @prop {Drupal~behaviorAttach} attach - * Attaches a check for the deprecated `message` property in the object - * returned by Drupal.evaluatePasswordStrength(). - */ - Drupal.behaviors.passwordThemeFunctionTest = { - attach(context, settings) { - const strength = Drupal.evaluatePasswordStrength( - 'password', - settings.password, - ); - - // eslint-disable-next-line no-unused-vars - const { message } = strength; - }, - }; -})(Drupal); diff --git a/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.js b/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.js deleted file mode 100644 index 676a0ae818ef..000000000000 --- a/core/modules/user/tests/themes/password_theme_function_test/js/password-theme-functions.js +++ /dev/null @@ -1,47 +0,0 @@ -/** -* DO NOT EDIT THIS FILE. -* See the following change record for more information, -* https://www.drupal.org/node/2815083 -* @preserve -**/ - -(Drupal => { - Drupal.theme.passwordStrength = _ref => { - let { - strengthTitle - } = _ref; - const strengthIndicator = '<span>Overridden passwordStrength:</span><div class="password-strength__indicator js-password-strength__indicator the-prior-class-is-deprecated" data-drupal-selector="a-distinct-absence-of-password-strength-indicator"></div>'; - const strengthText = '<span class="password-strength__text js-password-strength__text the-prior-class-is-deprecated" data-drupal-selector="a-distinct-absence-of-password-strength-text"></span>'; - return ` - <div class="password-strength"> - <div class="password-strength__meter" data-drupal-selector="password-strength-meter">${strengthIndicator}</div> - <div aria-live="polite" aria-atomic="true" class="password-strength__title">${strengthTitle} ${strengthText}</div> - </div> - `; - }; - - Drupal.theme.passwordSuggestions = (_ref2, tips) => { - let { - hasWeaknesses - } = _ref2; - return `<div class="password-suggestions">Overridden passwordSuggestions: ${tips.length ? `${hasWeaknesses}<ul><li>${tips.join('</li><li>')}</li></ul>` : ''}</div>`; - }; - - Drupal.theme.passwordConfirmMessage = _ref3 => { - let { - confirmTitle - } = _ref3; - const confirmTextWrapper = '<span>Overridden passwordConfirmMessage:</span><span data-drupal-selector="a-distinct-absence-of-password-match-status-text"></span>'; - return `<div aria-live="polite" aria-atomic="true" class="password-confirm-message" data-drupal-selector="password-confirm-message">${confirmTitle} ${confirmTextWrapper}</div>`; - }; - - Drupal.behaviors.passwordThemeFunctionTest = { - attach(context, settings) { - const strength = Drupal.evaluatePasswordStrength('password', settings.password); - const { - message - } = strength; - } - - }; -})(Drupal); \ No newline at end of file diff --git a/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.info.yml b/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.info.yml deleted file mode 100644 index c7e210f9cda6..000000000000 --- a/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.info.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: 'Password Theme Function Test theme' -type: theme -base theme: stark -description: 'Tests theme functions' -version: VERSION -libraries: - - password_theme_function_test/password-theme-functions diff --git a/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.libraries.yml b/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.libraries.yml deleted file mode 100644 index 3f2b7eec2231..000000000000 --- a/core/modules/user/tests/themes/password_theme_function_test/password_theme_function_test.libraries.yml +++ /dev/null @@ -1,6 +0,0 @@ -password-theme-functions: - js: - js/password-theme-functions.js: {} - dependencies: - - core/drupal - - user/drupal.user diff --git a/core/modules/user/user.es6.js b/core/modules/user/user.es6.js index cc8169b44d95..8652cc467d4e 100644 --- a/core/modules/user/user.es6.js +++ b/core/modules/user/user.es6.js @@ -76,16 +76,9 @@ Drupal.theme('passwordConfirmMessage', settings.password), ); - let $passwordMatchStatus = $passwordConfirmMessage + const $passwordMatchStatus = $passwordConfirmMessage .find('[data-drupal-selector="password-match-status-text"]') .first(); - if ($passwordMatchStatus.length === 0) { - $passwordMatchStatus = $passwordConfirmMessage.find('span').first(); - Drupal.deprecationError({ - message: - 'Returning <span> without data-drupal-selector="password-match-status-text" attribute is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3152101', - }); - } const $confirmInputParent = $confirmInput .parent() @@ -133,27 +126,9 @@ password.$strengthBar = $passwordStrength .find('[data-drupal-selector="password-strength-indicator"]') .first(); - if (password.$strengthBar.length === 0) { - password.$strengthBar = $passwordStrength - .find('.js-password-strength__indicator') - .first(); - Drupal.deprecationError({ - message: - 'The js-password-strength__indicator class is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Replace js-password-strength__indicator with a data-drupal-selector="password-strength-indicator" attribute. See https://www.drupal.org/node/3152101', - }); - } password.$strengthTextWrapper = $passwordStrength .find('[data-drupal-selector="password-strength-text"]') .first(); - if (password.$strengthTextWrapper.length === 0) { - password.$strengthTextWrapper = $passwordStrength - .find('.js-password-strength__text') - .first(); - Drupal.deprecationError({ - message: - 'The js-password-strength__text class is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Replace js-password-strength__text with a data-drupal-selector="password-strength-text" attribute. See https://www.drupal.org/node/3152101', - }); - } password.$suggestions = $( Drupal.theme('passwordSuggestions', settings.password, []), ); @@ -385,17 +360,11 @@ '</li><li>', )}</li></ul>`; - return Drupal.deprecatedProperty({ - target: { - strength, - message: msg, - indicatorText, - indicatorClass, - messageTips, - }, - deprecatedProperty: 'message', - message: - 'The message property is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. The markup should be constructed using messageTips property and Drupal.theme.passwordSuggestions. See https://www.drupal.org/node/3130352', - }); + return { + strength, + indicatorText, + indicatorClass, + messageTips, + }; }; })(jQuery, Drupal); diff --git a/core/modules/user/user.js b/core/modules/user/user.js index 73c501ba1d9d..d0ec474544b1 100644 --- a/core/modules/user/user.js +++ b/core/modules/user/user.js @@ -33,15 +33,7 @@ const $passwordWidget = $mainInput.closest('.js-form-type-password-confirm'); const $confirmInput = $passwordWidget.find('input.js-password-confirm'); const $passwordConfirmMessage = $(Drupal.theme('passwordConfirmMessage', settings.password)); - let $passwordMatchStatus = $passwordConfirmMessage.find('[data-drupal-selector="password-match-status-text"]').first(); - - if ($passwordMatchStatus.length === 0) { - $passwordMatchStatus = $passwordConfirmMessage.find('span').first(); - Drupal.deprecationError({ - message: 'Returning <span> without data-drupal-selector="password-match-status-text" attribute is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3152101' - }); - } - + const $passwordMatchStatus = $passwordConfirmMessage.find('[data-drupal-selector="password-match-status-text"]').first(); const $confirmInputParent = $confirmInput.parent().addClass('confirm-parent').append($passwordConfirmMessage); const passwordStrengthBarClassesToRemove = [cssClasses.passwordWeak || '', cssClasses.passwordFair || '', cssClasses.passwordGood || '', cssClasses.passwordStrong || ''].join(' ').trim(); const confirmTextWrapperClassesToRemove = [cssClasses.passwordsMatch || '', cssClasses.passwordsNotMatch || ''].join(' ').trim(); @@ -51,23 +43,7 @@ if (settings.password.showStrengthIndicator) { const $passwordStrength = $(Drupal.theme('passwordStrength', settings.password)); password.$strengthBar = $passwordStrength.find('[data-drupal-selector="password-strength-indicator"]').first(); - - if (password.$strengthBar.length === 0) { - password.$strengthBar = $passwordStrength.find('.js-password-strength__indicator').first(); - Drupal.deprecationError({ - message: 'The js-password-strength__indicator class is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Replace js-password-strength__indicator with a data-drupal-selector="password-strength-indicator" attribute. See https://www.drupal.org/node/3152101' - }); - } - password.$strengthTextWrapper = $passwordStrength.find('[data-drupal-selector="password-strength-text"]').first(); - - if (password.$strengthTextWrapper.length === 0) { - password.$strengthTextWrapper = $passwordStrength.find('.js-password-strength__text').first(); - Drupal.deprecationError({ - message: 'The js-password-strength__text class is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Replace js-password-strength__text with a data-drupal-selector="password-strength-text" attribute. See https://www.drupal.org/node/3152101' - }); - } - password.$suggestions = $(Drupal.theme('passwordSuggestions', settings.password, [])); password.$suggestions.hide(); $mainInputParent.append($passwordStrength); @@ -215,16 +191,11 @@ const messageTips = msg; msg = `${passwordSettings.hasWeaknesses}<ul><li>${msg.join('</li><li>')}</li></ul>`; - return Drupal.deprecatedProperty({ - target: { - strength, - message: msg, - indicatorText, - indicatorClass, - messageTips - }, - deprecatedProperty: 'message', - message: 'The message property is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. The markup should be constructed using messageTips property and Drupal.theme.passwordSuggestions. See https://www.drupal.org/node/3130352' - }); + return { + strength, + indicatorText, + indicatorClass, + messageTips + }; }; })(jQuery, Drupal); \ No newline at end of file diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 833cdc5be64a..7d1c7c3c6d99 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -218,25 +218,6 @@ function user_validate_name($name) { } } -/** - * Generate a random alphanumeric password. - * - * @param int $length - * The desired password length, in characters. - * - * @return string - * The generated random password. - * - * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use - * \Drupal\Core\Password\PasswordGeneratorInterface::generate() instead. - * - * @see https://www.drupal.org/node/3153113 - */ -function user_password($length = 10) { - @trigger_error('user_password() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Password\PasswordGeneratorInterface::generate() instead. See https://www.drupal.org/node/3153113', E_USER_DEPRECATED); - return \Drupal::service('password_generator')->generate($length); -} - /** * Determine the permissions for one or more roles. * @@ -1036,11 +1017,6 @@ function user_role_revoke_permissions($rid, array $permissions = []) { * @param \Drupal\Core\Session\AccountInterface $account * The user object of the account being notified. Must contain at * least the fields 'uid', 'name', and 'mail'. - * @param string $langcode - * (deprecated) (optional) Language code to use for the notification, - * overriding account language. Specifying the notification language using - * the $langcode parameter is deprecated in drupal:9.2.0 and is removed from - * drupal:10.0.0. Omit the parameter. See https://www.drupal.org/node/3187082 * * @return array * An array containing various information about the message. @@ -1048,14 +1024,10 @@ function user_role_revoke_permissions($rid, array $permissions = []) { * * @see user_mail_tokens() */ -function _user_mail_notify($op, AccountInterface $account, $langcode = NULL) { - if ($langcode) { - @trigger_error('Specifying the notification language using the $langcode parameter is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Omit the parameter. See https://www.drupal.org/node/3187082', E_USER_DEPRECATED); - } +function _user_mail_notify($op, AccountInterface $account) { if (\Drupal::config('user.settings')->get('notify.' . $op)) { $params['account'] = $account; - $langcode = $langcode ? $langcode : $account->getPreferredLangcode(); // Get the custom site notification email to use as the from email address // if it has been set. $site_mail = \Drupal::config('system.site')->get('mail_notification'); @@ -1067,7 +1039,7 @@ function _user_mail_notify($op, AccountInterface $account, $langcode = NULL) { if (empty($site_mail)) { $site_mail = ini_get('sendmail_from'); } - $mail = \Drupal::service('plugin.manager.mail')->mail('user', $op, $account->getEmail(), $langcode, $params, $site_mail); + $mail = \Drupal::service('plugin.manager.mail')->mail('user', $op, $account->getEmail(), $account->getPreferredLangcode(), $params, $site_mail); if ($op == 'register_pending_approval') { // If a user registered requiring admin approval, notify the admin, too. // We use the site default language for this. -- GitLab