class LegacyMessenger implements MessengerInterface (View source)

deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Messenger\Messenger instead.

Provides a LegacyMessenger implementation.

This implementation is for handling messages in a backwards compatible way using core's previous $_SESSION storage method.

You should not instantiate a new instance of this class directly. Instead, you should inject the "messenger" service into your own services or use \Drupal::messenger() in procedural functions.

Properties

static protected array $messages

The messages.

Methods

$this
addError(string|MarkupInterface $message, bool $repeat = FALSE)

Adds a new error message to the queue.

$this
addMessage(string|MarkupInterface $message, string $type = self::TYPE_STATUS, bool $repeat = FALSE)

Adds a new message to the queue.

$this
addStatus(string|MarkupInterface $message, bool $repeat = FALSE)

Adds a new status message to the queue.

$this
addWarning(string|MarkupInterface $message, bool $repeat = FALSE)

Adds a new warning message to the queue.

string[][]|MarkupInterface[][]
all()

Gets all messages.

getMessengerService()

Returns the Messenger service.

string[]|MarkupInterface[]
messagesByType(string $type)

Gets all messages of a certain type.

string[]|MarkupInterface[]
deleteAll()

Deletes all messages.

string[]|MarkupInterface[]
deleteByType(string $type)

Deletes all messages of a certain type.

Details

$this addError(string|MarkupInterface $message, bool $repeat = FALSE)

Adds a new error message to the queue.

Parameters

string|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.

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

$this addMessage(string|MarkupInterface $message, string $type = self::TYPE_STATUS, bool $repeat = FALSE)

Adds a new message to the queue.

The messages will be displayed in the order they got added later.

Parameters

string|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

$this addStatus(string|MarkupInterface $message, bool $repeat = FALSE)

Adds a new status message to the queue.

Parameters

string|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.

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

$this addWarning(string|MarkupInterface $message, bool $repeat = FALSE)

Adds a new warning message to the queue.

Parameters

string|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.

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

string[][]|MarkupInterface[][] all()

Gets all messages.

Return Value

string[][]|MarkupInterface[][]

Keys are message types and values are indexed arrays of messages. Message types are either self::TYPE_STATUS, self::TYPE_WARNING, or self::TYPE_ERROR.

protected MessengerInterface|null getMessengerService()

Returns the Messenger service.

Return Value

MessengerInterface|null

The Messenger service.

string[]|MarkupInterface[] messagesByType(string $type)

Gets all messages of a certain type.

Parameters

string $type

The messages' type. Either self::TYPE_STATUS, self::TYPE_WARNING, or self::TYPE_ERROR.

Return Value

string[]|MarkupInterface[]

The messages of given type.

string[]|MarkupInterface[] deleteAll()

Deletes all messages.

Return Value

string[]|MarkupInterface[]

The deleted messages.

string[]|MarkupInterface[] deleteByType(string $type)

Deletes all messages of a certain type.

Parameters

string $type

The messages' type. Either self::TYPE_STATUS, self::TYPE_WARNING, or self::TYPE_ERROR.

Return Value

string[]|MarkupInterface[]

The deleted messages of given type.