MessengerInterface.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace Drupal\Core\Messenger;
  3. /**
  4. * Stores runtime messages sent out to individual users on the page.
  5. *
  6. * An example for these messages is for example: "Content X got saved".
  7. */
  8. interface MessengerInterface {
  9. /**
  10. * A status message.
  11. */
  12. const TYPE_STATUS = 'status';
  13. /**
  14. * A warning.
  15. */
  16. const TYPE_WARNING = 'warning';
  17. /**
  18. * An error.
  19. */
  20. const TYPE_ERROR = 'error';
  21. /**
  22. * Adds a new message to the queue.
  23. *
  24. * The messages will be displayed in the order they got added later.
  25. *
  26. * @param string|\Drupal\Component\Render\MarkupInterface $message
  27. * (optional) The translated message to be displayed to the user. For
  28. * consistency with other messages, it should begin with a capital letter
  29. * and end with a period.
  30. * @param string $type
  31. * (optional) The message's type. Either self::TYPE_STATUS,
  32. * self::TYPE_WARNING, or self::TYPE_ERROR.
  33. * @param bool $repeat
  34. * (optional) If this is FALSE and the message is already set, then the
  35. * message won't be repeated. Defaults to FALSE.
  36. *
  37. * @return $this
  38. */
  39. public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE);
  40. /**
  41. * Adds a new status message to the queue.
  42. *
  43. * @param string|\Drupal\Component\Render\MarkupInterface $message
  44. * (optional) The translated message to be displayed to the user. For
  45. * consistency with other messages, it should begin with a capital letter
  46. * and end with a period.
  47. * @param bool $repeat
  48. * (optional) If this is FALSE and the message is already set, then the
  49. * message won't be repeated. Defaults to FALSE.
  50. *
  51. * @return $this
  52. */
  53. public function addStatus($message, $repeat = FALSE);
  54. /**
  55. * Adds a new error message to the queue.
  56. *
  57. * @param string|\Drupal\Component\Render\MarkupInterface $message
  58. * (optional) The translated message to be displayed to the user. For
  59. * consistency with other messages, it should begin with a capital letter
  60. * and end with a period.
  61. * @param bool $repeat
  62. * (optional) If this is FALSE and the message is already set, then the
  63. * message won't be repeated. Defaults to FALSE.
  64. *
  65. * @return $this
  66. */
  67. public function addError($message, $repeat = FALSE);
  68. /**
  69. * Adds a new warning message to the queue.
  70. *
  71. * @param string|\Drupal\Component\Render\MarkupInterface $message
  72. * (optional) The translated message to be displayed to the user. For
  73. * consistency with other messages, it should begin with a capital letter
  74. * and end with a period.
  75. * @param bool $repeat
  76. * (optional) If this is FALSE and the message is already set, then the
  77. * message won't be repeated. Defaults to FALSE.
  78. *
  79. * @return $this
  80. */
  81. public function addWarning($message, $repeat = FALSE);
  82. /**
  83. * Gets all messages.
  84. *
  85. * @return string[][]|\Drupal\Component\Render\MarkupInterface[][]
  86. * Keys are message types and values are indexed arrays of messages. Message
  87. * types are either self::TYPE_STATUS, self::TYPE_WARNING, or
  88. * self::TYPE_ERROR.
  89. */
  90. public function all();
  91. /**
  92. * Gets all messages of a certain type.
  93. *
  94. * @param string $type
  95. * The messages' type. Either self::TYPE_STATUS, self::TYPE_WARNING,
  96. * or self::TYPE_ERROR.
  97. *
  98. * @return string[]|\Drupal\Component\Render\MarkupInterface[]
  99. * The messages of given type.
  100. */
  101. public function messagesByType($type);
  102. /**
  103. * Deletes all messages.
  104. *
  105. * @return string[]|\Drupal\Component\Render\MarkupInterface[]
  106. * The deleted messages.
  107. */
  108. public function deleteAll();
  109. /**
  110. * Deletes all messages of a certain type.
  111. *
  112. * @param string $type
  113. * The messages' type. Either self::TYPE_STATUS, self::TYPE_WARNING, or
  114. * self::TYPE_ERROR.
  115. *
  116. * @return string[]|\Drupal\Component\Render\MarkupInterface[]
  117. * The deleted messages of given type.
  118. */
  119. public function deleteByType($type);
  120. }