_authSession = $authSession; $this->_criticalCollection = $criticalCollection; $this->_isScopePrivate = true; } /** * Render block * * @return string */ protected function _toHtml() { if ($this->canShow()) { $this->setHeaderText($this->escapeHtml(__('Incoming Message'))); $this->setCloseText($this->escapeHtml(__('close'))); $this->setReadDetailsText($this->escapeHtml(__('Read Details'))); $this->setNoticeMessageText($this->escapeHtml($this->_getLatestItem()->getTitle())); $this->setNoticeMessageUrl($this->escapeUrl($this->_getLatestItem()->getUrl())); $this->setSeverityText('critical'); return parent::_toHtml(); } return ''; } /** * Retrieve latest critical item * * @return bool|\Magento\Adminnotification\Model\Inbox */ protected function _getLatestItem() { if ($this->_latestItem == null) { $items = array_values($this->_criticalCollection->getItems()); if (count($items)) { $this->_latestItem = $items[0]; } else { $this->_latestItem = false; } } return $this->_latestItem; } /** * Check whether block should be displayed * * @return bool */ public function canShow() { return $this->_authSession->isFirstPageAfterLogin() && $this->_getLatestItem(); } }