28 private $cookieManager;
33 private $cookieMetadataFactory;
38 private $messageManager;
43 private $interpretationStrategy;
53 private $inlineTranslate;
64 \
Magento\Framework\Stdlib\CookieManagerInterface $cookieManager,
65 \
Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory,
66 \
Magento\Framework\Message\ManagerInterface $messageManager,
67 \
Magento\Framework\View\Element\Message\InterpretationStrategyInterface $interpretationStrategy,
71 $this->cookieManager = $cookieManager;
72 $this->cookieMetadataFactory = $cookieMetadataFactory;
73 $this->messageManager = $messageManager;
76 $this->interpretationStrategy = $interpretationStrategy;
94 if (!($subject instanceof
Json)) {
95 $this->setCookie($this->getMessages());
123 private function setCookie(array $messages)
125 if (!empty($messages)) {
126 if ($this->inlineTranslate->isAllowed()) {
132 $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
133 $publicCookieMetadata->setDurationOneYear();
134 $publicCookieMetadata->setPath(
'/');
135 $publicCookieMetadata->setHttpOnly(
false);
137 $this->cookieManager->setPublicCookie(
138 self::MESSAGES_COOKIES_NAME,
139 $this->serializer->serialize($messages),
140 $publicCookieMetadata
151 private function convertMessageText(
string $text): string
165 protected function getMessages()
169 foreach ($this->messageManager->getMessages(
true)->getItems() as
$message) {
172 'text' => $this->interpretationStrategy->interpret(
$message),
185 $messages = $this->cookieManager->getCookie(self::MESSAGES_COOKIES_NAME);
189 $messages = $this->serializer->unserialize($messages);
190 if (!is_array($messages)) {
__construct(\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\Framework\View\Element\Message\InterpretationStrategyInterface $interpretationStrategy, \Magento\Framework\Serialize\Serializer\Json $serializer=null, InlineInterface $inlineTranslate=null)
afterRenderResult(ResultInterface $subject, ResultInterface $result)
const MESSAGES_COOKIES_NAME