diff --git a/app/code/Magento/AdminNotification/Controller/Adminhtml/System/Message/ListAction.php b/app/code/Magento/AdminNotification/Controller/Adminhtml/System/Message/ListAction.php index 76c6d2c5e783f..c40ff5a1659cc 100644 --- a/app/code/Magento/AdminNotification/Controller/Adminhtml/System/Message/ListAction.php +++ b/app/code/Magento/AdminNotification/Controller/Adminhtml/System/Message/ListAction.php @@ -8,36 +8,56 @@ class ListAction extends \Magento\Backend\App\AbstractAction { + /** + * @var \Magento\Framework\Json\Helper\Data + */ + protected $jsonHelper; + + /** + * @var \Magento\AdminNotification\Model\Resource\System\Message\Collection + */ + protected $messageCollection; + + /** + * Initialize ListAction + * + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\Json\Helper\Data $jsonHelper + * @param \Magento\AdminNotification\Model\Resource\System\Message\Collection $messageCollection + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\Json\Helper\Data $jsonHelper, + \Magento\AdminNotification\Model\Resource\System\Message\Collection $messageCollection + ) { + $this->jsonHelper = $jsonHelper; + $this->messageCollection = $messageCollection; + parent::__construct($context); + } + /** * @return void */ public function execute() { $severity = $this->getRequest()->getParam('severity'); - $default = [ - 'severity' => $severity, - 'text' => 'All recent issues have been fixed. ' - .'Please refresh the screen for an update.', - ]; - $messageCollection = $this->_objectManager->get( - 'Magento\AdminNotification\Model\Resource\System\Message\Collection' - ); if ($severity) { - $messageCollection->setSeverity($severity); + $this->messageCollection->setSeverity($severity); } $result = []; - foreach ($messageCollection->getItems() as $item) { + foreach ($this->messageCollection->getItems() as $item) { $result[] = [ 'severity' => $item->getSeverity(), 'text' => $item->getText(), ]; } if (empty($result)) { - $result[] = $default; + $result[] = [ + 'severity' => (string)\Magento\Framework\Notification\MessageInterface::SEVERITY_NOTICE, + 'text' => 'You have viewed and resolved all recent system notices. ' + . 'Please refresh the web page to clear the notice alert.', + ]; } - $this->getResponse()->representJson( - $this->_objectManager->get('Magento\Framework\Json\Helper\Data') - ->jsonEncode($result) - ); + $this->getResponse()->representJson($this->jsonHelper->jsonEncode($result)); } }