diff -u b/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php --- b/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -16,6 +16,8 @@ use Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser; use Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin; use Symfony\Component\DependencyInjection\ContainerInterface; +// use Drupal\Core\Messenger\Messenger; +use Drupal\Core\Messenger\MessengerInterface; /** * Form controller for the user account forms. @@ -30,6 +32,14 @@ protected $languageManager; /** + * The Message service. + * + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + + protected $messenger; + + /** * Constructs a new EntityForm object. * * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository @@ -41,9 +51,10 @@ * @param \Drupal\Component\Datetime\TimeInterface $time * The time service. */ - public function __construct(EntityRepositoryInterface $entity_repository, LanguageManagerInterface $language_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) { + public function __construct(EntityRepositoryInterface $entity_repository, LanguageManagerInterface $language_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL,MessengerInterface $messengerManager) { parent::__construct($entity_repository, $entity_type_bundle_info, $time); $this->languageManager = $language_manager; + $this->messenger = $messengerManager; } /** @@ -54,7 +65,8 @@ $container->get('entity.repository'), $container->get('language_manager'), $container->get('entity_type.bundle.info'), - $container->get('datetime.time') + $container->get('datetime.time'), + $container->get('messenger') ); } @@ -209,8 +221,7 @@ ]; if ($account->id() == 1) { - $messenger = \Drupal::messenger(); - $messenger->addMessage($this->t('Be careful, you are editing the admin user. Changes made here could lock you out of your site completely.'), $messenger::TYPE_WARNING); + $this->messenger->addMessage($this->t('Be careful, you are editing the admin user. Changes made here could lock you out of your site completely.'), $this->messenger::TYPE_WARNING); } // Special handling for the inevitable "Authenticated user" role. $form['account']['roles'][RoleInterface::AUTHENTICATED_ID] = [