1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- /**
- * Copyright © 2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
- * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
- *
- * Glory to Ukraine! Glory to the heroes!
- */
- namespace Magefan\Blog\Observer;
- use Magento\Framework\Event\ObserverInterface;
- use Magento\Framework\Data\Tree\Node;
- use Magento\Store\Model\ScopeInterface;
- use Magefan\Blog\Helper\Config;
- /**
- * Blog observer
- */
- class PageBlockHtmlTopmenuBethtmlBeforeObserver implements ObserverInterface
- {
- /**
- * Show top menu item config path
- */
- const XML_PATH_TOP_MENU_SHOW_ITEM = 'mfblog/top_menu/show_item';
- /**
- * Top menu item text config path
- */
- const XML_PATH_TOP_MENU_ITEM_TEXT = 'mfblog/top_menu/item_text';
- /**
- * @var \Magefan\Blog\Model\Url
- */
- protected $_url;
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
- */
- protected $_scopeConfig;
- /**
- * @param \Magefan\Blog\Model\Url $url
- */
- public function __construct(
- \Magefan\Blog\Model\Url $url,
- \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
- ) {
- $this->_scopeConfig = $scopeConfig;
- $this->_url = $url;
- }
- /**
- * Page block html topmenu gethtml before
- *
- * @param \Magento\Framework\Event\Observer $observer
- * @return void
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function execute(\Magento\Framework\Event\Observer $observer)
- {
- if (!$this->_scopeConfig->isSetFlag(static::XML_PATH_TOP_MENU_SHOW_ITEM, ScopeInterface::SCOPE_STORE)) {
- return;
- }
- if (!$this->_scopeConfig->isSetFlag(Config::XML_PATH_EXTENSION_ENABLED, ScopeInterface::SCOPE_STORE)) {
- return;
- }
- /** @var \Magento\Framework\Data\Tree\Node $menu */
- $menu = $observer->getMenu();
- $block = $observer->getBlock();
- $tree = $menu->getTree();
- $data = [
- 'name' => $this->_scopeConfig->getValue(static::XML_PATH_TOP_MENU_ITEM_TEXT, ScopeInterface::SCOPE_STORE),
- 'id' => 'magefan-blog',
- 'url' => $this->_url->getBaseUrl(),
- 'is_active' => ($block->getRequest()->getModuleName() == 'blog'),
- ];
- $node = new Node($data, 'id', $tree, $menu);
- $menu->addChild($node);
- }
- }
|