|
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 |
| - $default = [ |
18 |
| - 'severity' => $severity, |
19 |
| - 'text' => 'All recent issues have been fixed. ' |
20 |
| - .'Please refresh the screen for an update.', |
21 |
| - ]; |
22 |
| - $messageCollection = $this->_objectManager->get( |
23 |
| - 'Magento\AdminNotification\Model\Resource\System\Message\Collection' |
24 |
| - ); |
25 | 44 | if ($severity) {
|
26 |
| - $messageCollection->setSeverity($severity); |
| 45 | + $this->messageCollection->setSeverity($severity); |
27 | 46 | }
|
28 | 47 | $result = [];
|
29 |
| - foreach ($messageCollection->getItems() as $item) { |
| 48 | + foreach ($this->messageCollection->getItems() as $item) { |
30 | 49 | $result[] = [
|
31 | 50 | 'severity' => $item->getSeverity(),
|
32 | 51 | 'text' => $item->getText(),
|
33 | 52 | ];
|
34 | 53 | }
|
35 | 54 | if (empty($result)) {
|
36 |
| - $result[] = $default; |
| 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 | + ]; |
37 | 60 | }
|
38 |
| - $this->getResponse()->representJson( |
39 |
| - $this->_objectManager->get('Magento\Framework\Json\Helper\Data') |
40 |
| - ->jsonEncode($result) |
41 |
| - ); |
| 61 | + $this->getResponse()->representJson($this->jsonHelper->jsonEncode($result)); |
42 | 62 | }
|
43 | 63 | }
|
0 commit comments