helper = $helper; $this->pageConfig = $pageConfig; $this->registry = $registry; $this->objectManager = $objectManager; $this->urlManager = $urlManager; $this->context = $context; $this->url = $url; $this->storeGroup = $storeGroup; } /** * @param \Magento\Framework\Event\Observer $observer * * @return $this */ public function execute(Observer $observer) { $this->basicSetup($observer); return $this; } /** * @return mixed */ public function getBaseUrl() { return $this->objectManager->get( 'Magento\Store\Model\StoreManagerInterface' )->getStore()->getBaseUrl(); } /** * @param $observer */ public function basicSetup($observer) { /** * @var \Magento\Framework\View\LayoutInterface */ $layout = $observer->getEvent()->getLayout(); $action = $observer->getEvent()->getFullActionName(); /** * catalog_category_view * vendor/magento/module-catalog/Block/Category/View.php:72 */ if ($action == 'catalog_category_view') { $category = $this->registry->registry('current_category'); $pageRobots = $category->getMpMetaRobots(); } /** * catalog_product_view * vendor/magento/module-catalog/Block/Product/View.php:135 */ if ($action == 'catalog_product_view') { $product = $this->registry->registry('current_product'); $pageRobots = $product->getMpMetaRobots(); } /** * home page cms page */ if ($action == 'cms_index_index' or $action == 'cms_page_view') { $page = $this->objectManager->get( 'Magento\Cms\Model\Page' ); $pageRobots = $page->getMpMetaRobots(); if ($action == 'cms_index_index') { $url = $this->urlManager->getBaseUrl(); } else { $url = $this->urlManager->getUrl($page->getIdentifier()); } } if (!empty($pageRobots)) { $this->pageConfig->setRobots($pageRobots); } } /** * @return mixed */ public function getLangCode() { $code = $this->storeGroup->getDefaultStore()->getLocaleCode(); $code = strtolower($code); return $code; } }