function LegacyMessenger::addMessage

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.