Skip to content
Snippets Groups Projects
Commit b9edf92b authored by catch's avatar catch
Browse files

Issue #2937945 by yo30, kim.pepper, dawehner, voleger, larowlan: Add messenger...

Issue #2937945 by yo30, kim.pepper, dawehner, voleger, larowlan: Add messenger to ControllerBase and FormBase
parent 974d0f91
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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;
......
......@@ -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;
......
<?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;
}
}
......@@ -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');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment