|
8 | 8 |
|
9 | 9 | class ListAction extends \Magento\Backend\App\AbstractAction
|
10 | 10 | {
|
| 11 | + /** |
| 12 | + * @var \Magento\Framework\Json\Helper\Data |
| 13 | + */ |
| 14 | + protected $jsonHelper; |
| 15 | + |
| 16 | + /** |
| 17 | + * @var \Magento\AdminNotification\Model\Resource\System\Message\Collection |
| 18 | + */ |
| 19 | + protected $messageCollection; |
| 20 | + |
| 21 | + /** |
| 22 | + * Initialize ListAction |
| 23 | + * |
| 24 | + * @param \Magento\Backend\App\Action\Context $context |
| 25 | + * @param \Magento\Framework\Json\Helper\Data $jsonHelper |
| 26 | + * @param \Magento\AdminNotification\Model\Resource\System\Message\Collection $messageCollection |
| 27 | + */ |
| 28 | + public function __construct( |
| 29 | + \Magento\Backend\App\Action\Context $context, |
| 30 | + \Magento\Framework\Json\Helper\Data $jsonHelper, |
| 31 | + \Magento\AdminNotification\Model\Resource\System\Message\Collection $messageCollection |
| 32 | + ) { |
| 33 | + $this->jsonHelper = $jsonHelper; |
| 34 | + $this->messageCollection = $messageCollection; |
| 35 | + parent::__construct($context); |
| 36 | + } |
| 37 | + |
11 | 38 | /**
|
12 | 39 | * @return void
|
13 | 40 | */
|
14 | 41 | public function execute()
|
15 | 42 | {
|
16 | 43 | $severity = $this->getRequest()->getParam('severity');
|
17 |
| - $messageCollection = $this->_objectManager->get( |
18 |
| - 'Magento\AdminNotification\Model\Resource\System\Message\Collection' |
19 |
| - ); |
20 | 44 | if ($severity) {
|
21 |
| - $messageCollection->setSeverity($severity); |
| 45 | + $this->messageCollection->setSeverity($severity); |
22 | 46 | }
|
23 | 47 | $result = [];
|
24 |
| - foreach ($messageCollection->getItems() as $item) { |
25 |
| - $result[] = ['severity' => $item->getSeverity(), 'text' => $item->getText()]; |
| 48 | + foreach ($this->messageCollection->getItems() as $item) { |
| 49 | + $result[] = [ |
| 50 | + 'severity' => $item->getSeverity(), |
| 51 | + 'text' => $item->getText(), |
| 52 | + ]; |
| 53 | + } |
| 54 | + if (empty($result)) { |
| 55 | + $result[] = [ |
| 56 | + 'severity' => (string)\Magento\Framework\Notification\MessageInterface::SEVERITY_NOTICE, |
| 57 | + 'text' => 'You have viewed and resolved all recent system notices. ' |
| 58 | + . 'Please refresh the web page to clear the notice alert.', |
| 59 | + ]; |
26 | 60 | }
|
27 |
| - $this->getResponse()->representJson( |
28 |
| - $this->_objectManager->get('Magento\Framework\Json\Helper\Data')->jsonEncode($result) |
29 |
| - ); |
| 61 | + $this->getResponse()->representJson($this->jsonHelper->jsonEncode($result)); |
30 | 62 | }
|
31 | 63 | }
|
0 commit comments