3 namespace Drupal\Core\Messenger;
6 * Stores runtime messages sent out to individual users on the page.
8 * An example for these messages is for example: "Content X got saved".
10 interface MessengerInterface {
15 const TYPE_STATUS = 'status';
20 const TYPE_WARNING = 'warning';
25 const TYPE_ERROR = 'error';
28 * Adds a new message to the queue.
30 * The messages will be displayed in the order they got added later.
32 * @param string|\Drupal\Component\Render\MarkupInterface $message
33 * (optional) The translated message to be displayed to the user. For
34 * consistency with other messages, it should begin with a capital letter
35 * and end with a period.
37 * (optional) The message's type. Either self::TYPE_STATUS,
38 * self::TYPE_WARNING, or self::TYPE_ERROR.
40 * (optional) If this is FALSE and the message is already set, then the
41 * message won't be repeated. Defaults to FALSE.
45 public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE);
48 * Adds a new status message to the queue.
50 * @param string|\Drupal\Component\Render\MarkupInterface $message
51 * (optional) The translated message to be displayed to the user. For
52 * consistency with other messages, it should begin with a capital letter
53 * and end with a period.
55 * (optional) If this is FALSE and the message is already set, then the
56 * message won't be repeated. Defaults to FALSE.
60 public function addStatus($message, $repeat = FALSE);
63 * Adds a new error message to the queue.
65 * @param string|\Drupal\Component\Render\MarkupInterface $message
66 * (optional) The translated message to be displayed to the user. For
67 * consistency with other messages, it should begin with a capital letter
68 * and end with a period.
70 * (optional) If this is FALSE and the message is already set, then the
71 * message won't be repeated. Defaults to FALSE.
75 public function addError($message, $repeat = FALSE);
78 * Adds a new warning message to the queue.
80 * @param string|\Drupal\Component\Render\MarkupInterface $message
81 * (optional) The translated message to be displayed to the user. For
82 * consistency with other messages, it should begin with a capital letter
83 * and end with a period.
85 * (optional) If this is FALSE and the message is already set, then the
86 * message won't be repeated. Defaults to FALSE.
90 public function addWarning($message, $repeat = FALSE);
95 * @return string[][]|\Drupal\Component\Render\MarkupInterface[][]
96 * Keys are message types and values are indexed arrays of messages. Message
97 * types are either self::TYPE_STATUS, self::TYPE_WARNING, or
100 public function all();
103 * Gets all messages of a certain type.
105 * @param string $type
106 * The messages' type. Either self::TYPE_STATUS, self::TYPE_WARNING,
107 * or self::TYPE_ERROR.
109 * @return string[]|\Drupal\Component\Render\MarkupInterface[]
110 * The messages of given type.
112 public function messagesByType($type);
115 * Deletes all messages.
117 * @return string[]|\Drupal\Component\Render\MarkupInterface[]
118 * The deleted messages.
120 public function deleteAll();
123 * Deletes all messages of a certain type.
125 * @param string $type
126 * The messages' type. Either self::TYPE_STATUS, self::TYPE_WARNING, or
129 * @return string[]|\Drupal\Component\Render\MarkupInterface[]
130 * The deleted messages of given type.
132 public function deleteByType($type);