MessengerInterface.php 2.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
<?php

namespace Drupal\Core\Messenger;

/**
 * Stores runtime messages sent out to individual users on the page.
 *
 * An example for these messages is for example: "Content X got saved".
 */
interface MessengerInterface {

  /**
   * A status message.
   */
  const TYPE_STATUS = 'status';

  /**
   * A warning.
   */
  const TYPE_WARNING = 'warning';

  /**
   * An error.
   */
  const TYPE_ERROR = 'error';

  /**
   * Adds a new message to the queue.
   *
   * @param 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.
   * @param string $type
   *   (optional) The message's type. Either self::TYPE_STATUS,
   *   self::TYPE_WARNING, or self::TYPE_ERROR.
   * @param bool $repeat
   *   (optional) If this is FALSE and the message is already set, then the
   *   message won't be repeated. Defaults to FALSE.
   *
   * @return $this
   */
  public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE);

  /**
   * Gets all messages.
   *
   * @return string[][]|\Drupal\Component\Render\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.
   */
  public function getMessages();

  /**
   * Gets all messages of a certain type.
   *
   * @param string $type
   *   The messages' type. Either self::TYPE_STATUS, self::TYPE_WARNING,
   *   or self::TYPE_ERROR.
   *
   * @return string[]|\Drupal\Component\Render\MarkupInterface[]
   */
  public function getMessagesByType($type);

  /**
   * Deletes all messages.
   *
   * @return $this
   */
  public function deleteMessages();

  /**
   * Deletes all messages of a certain type.
   *
   * @param string $type
   *   The messages' type. Either self::TYPE_STATUS, self::TYPE_WARNING, or
   *   self::TYPE_ERROR.
   *
   * @return $this
   */
  public function deleteMessagesByType($type);

}