diff --git a/core/lib/Drupal/Core/Controller/ControllerBase.php b/core/lib/Drupal/Core/Controller/ControllerBase.php index c0d0cdd964b10149a1a4b38919bd113a7d24bc64..241936753a7afc628ce26071f96b06772619c3e7 100644 --- a/core/lib/Drupal/Core/Controller/ControllerBase.php +++ b/core/lib/Drupal/Core/Controller/ControllerBase.php @@ -9,6 +9,7 @@ use Drupal\Core\Routing\UrlGeneratorTrait; use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Messenger\MessengerTrait; /** * Utility base class for thin controllers. @@ -35,6 +36,7 @@ abstract class ControllerBase implements ContainerInjectionInterface { use LinkGeneratorTrait; use LoggerChannelTrait; + use MessengerTrait; use RedirectDestinationTrait; use StringTranslationTrait; use UrlGeneratorTrait; diff --git a/core/lib/Drupal/Core/Form/FormBase.php b/core/lib/Drupal/Core/Form/FormBase.php index 02a1c3940c40d61449432be121e7efb3fa141517..165cb3a8f0cf7c876e9b4ee4349590ac5a555acb 100644 --- a/core/lib/Drupal/Core/Form/FormBase.php +++ b/core/lib/Drupal/Core/Form/FormBase.php @@ -12,6 +12,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; +use Drupal\Core\Messenger\MessengerTrait; /** * Provides a base class for forms. @@ -45,6 +46,7 @@ abstract class FormBase implements FormInterface, ContainerInjectionInterface { use DependencySerializationTrait; use LinkGeneratorTrait; use LoggerChannelTrait; + use MessengerTrait; use RedirectDestinationTrait; use StringTranslationTrait; use UrlGeneratorTrait; diff --git a/core/lib/Drupal/Core/Messenger/MessengerTrait.php b/core/lib/Drupal/Core/Messenger/MessengerTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..1454243b8fd749b2f009ba22ecd2336f14e2bdec --- /dev/null +++ b/core/lib/Drupal/Core/Messenger/MessengerTrait.php @@ -0,0 +1,40 @@ +<?php + +namespace Drupal\Core\Messenger; + +/** + * Provides a trait for the messenger service. + */ +trait MessengerTrait { + + /** + * The messenger. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + + /** + * Sets the messenger. + * + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * The messenger. + */ + public function setMessenger(MessengerInterface $messenger) { + $this->messenger = $messenger; + } + + /** + * Gets the messenger. + * + * @return \Drupal\Core\Messenger\MessengerInterface + * The messenger. + */ + public function messenger() { + if (!isset($this->messenger)) { + $this->messenger = \Drupal::messenger(); + } + return $this->messenger; + } + +} diff --git a/core/modules/aggregator/src/Controller/AggregatorController.php b/core/modules/aggregator/src/Controller/AggregatorController.php index b459b196ccbd441011649218a73f73ec7dbd91e7..7fd0743881f1d897537153897eb114ba371f1c88 100644 --- a/core/modules/aggregator/src/Controller/AggregatorController.php +++ b/core/modules/aggregator/src/Controller/AggregatorController.php @@ -93,7 +93,7 @@ public function feedRefresh(FeedInterface $aggregator_feed) { $message = $aggregator_feed->refreshItems() ? $this->t('There is new syndicated content from %site.', ['%site' => $aggregator_feed->label()]) : $this->t('There is no new syndicated content from %site.', ['%site' => $aggregator_feed->label()]); - drupal_set_message($message); + $this->messenger()->addStatus($message); return $this->redirect('aggregator.admin_overview'); }