Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Messages.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Framework\Message\ManagerInterface as MessageManager;
13 
18 {
24  protected $messageManager;
25 
29  private $interpretationStrategy;
30 
37  public function __construct(
38  MessageManager $messageManager,
39  InterpretationStrategyInterface $interpretationStrategy
40  ) {
41  $this->messageManager = $messageManager;
42  $this->interpretationStrategy = $interpretationStrategy;
43  }
44 
48  public function getSectionData()
49  {
50  $messages = $this->messageManager->getMessages(true);
51  return [
52  'messages' => array_reduce(
53  $messages->getItems(),
54  function (array $result, MessageInterface $message) {
55  $result[] = [
56  'type' => $message->getType(),
57  'text' => $this->interpretationStrategy->interpret($message)
58  ];
59  return $result;
60  },
61  []
62  ),
63  ];
64  }
65 }
$message
__construct(MessageManager $messageManager, InterpretationStrategyInterface $interpretationStrategy)
Definition: Messages.php:37