You are here

public function LegacyMessenger::addMessage in Drupal 8

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 LegacyMessenger::addMessage()
LegacyMessenger::addError in core/lib/Drupal/Core/Messenger/LegacyMessenger.php
Adds a new error message to the queue.
LegacyMessenger::addStatus in core/lib/Drupal/Core/Messenger/LegacyMessenger.php
Adds a new status message to the queue.
LegacyMessenger::addWarning in core/lib/Drupal/Core/Messenger/LegacyMessenger.php
Adds a new warning message to the queue.

File

core/lib/Drupal/Core/Messenger/LegacyMessenger.php, line 47

Class

LegacyMessenger
Provides a LegacyMessenger implementation.

Namespace

Drupal\Core\Messenger

Code

public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE) {

  // Proxy to the Messenger service, if it exists.
  if ($messenger = $this
    ->getMessengerService()) {
    return $messenger
      ->addMessage($message, $type, $repeat);
  }
  if (!isset(static::$messages[$type])) {
    static::$messages[$type] = [];
  }
  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, static::$messages[$type])) {
    static::$messages[$type][] = $message;
  }
  return $this;
}