public function Messenger::addMessage in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Messenger/Messenger.php \Drupal\Core\Messenger\Messenger::addMessage()
Adds a new message to the queue.
The messages will be displayed in the order they got added later.
Parameters
string|\Drupal\Component\Render\MarkupInterface $message: (optional) The translated message to be displayed to the user. For consistency with other messages, it should begin with a capital letter and end with a period.
string $type: (optional) The message's type. Either self::TYPE_STATUS, self::TYPE_WARNING, or self::TYPE_ERROR.
bool $repeat: (optional) If this is FALSE and the message is already set, then the message won't be repeated. Defaults to FALSE.
Return value
$this
Overrides MessengerInterface::addMessage
3 calls to Messenger::addMessage()
- Messenger::addError in core/
lib/ Drupal/ Core/ Messenger/ Messenger.php - Adds a new error message to the queue.
- Messenger::addStatus in core/
lib/ Drupal/ Core/ Messenger/ Messenger.php - Adds a new status message to the queue.
- Messenger::addWarning in core/
lib/ Drupal/ Core/ Messenger/ Messenger.php - Adds a new warning message to the queue.
File
- core/
lib/ Drupal/ Core/ Messenger/ Messenger.php, line 52
Class
- Messenger
- The messenger service.
Namespace
Drupal\Core\MessengerCode
public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE) {
if (!$message instanceof Markup && $message instanceof MarkupInterface) {
$message = Markup::create((string) $message);
}
// Do not use strict type checking so that equivalent string and
// MarkupInterface objects are detected.
if ($repeat || !in_array($message, $this->flashBag
->peek($type))) {
$this->flashBag
->add($type, $message);
}
// Mark this page as being uncacheable.
$this->killSwitch
->trigger();
return $this;
}