/** * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _prepareLayout() { parent::_prepareLayout(); $category = $this->getCategory(); $title = $category ? $category->getName() : $this->config->getBlogName(); $metaTitle = $category ? $category->getMetaTitle() ? $category->getMetaTitle() : $category->getName() : $this->config->getBaseMetaTitle(); $metaDescription = $category ? $category->getMetaDescription() ? $category->getMetaDescription() : $category->getName() : $this->config->getBaseMetaDescription(); $metaKeywords = $category ? $category->getMetaKeywords() ? $category->getMetaKeywords() : $category->getName() : $this->config->getBaseMetaKeywords(); $this->pageConfig->getTitle()->set($metaTitle); $this->pageConfig->setDescription($metaDescription); $this->pageConfig->setKeywords($metaKeywords); /** @var \Magento\Theme\Block\Html\Title $pageMainTitle */ $pageMainTitle = $this->getLayout()->getBlock('page.main.title'); if ($pageMainTitle) { $pageMainTitle->setPageTitle($title); } /** @var \Magento\Theme\Block\Html\Breadcrumbs $breadcrumbs */ if ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) { $breadcrumbs->addCrumb('home', ['label' => __('Home'), 'title' => __('Go to Home Page'), 'link' => $this->context->getUrlBuilder()->getBaseUrl()])->addCrumb('blog', ['label' => $this->config->getBlogName(), 'title' => $this->config->getBlogName(), 'link' => $this->config->getBaseUrl()]); if ($category) { $ids = $category->getParentIds(); $ids[] = 0; $parents = $this->categoryCollectionFactory->create()->addFieldToFilter('entity_id', $ids)->addNameToSelect()->excludeRoot()->setOrder('level', 'asc'); /** @var \Mirasvit\Blog\Model\Category $cat */ foreach ($parents as $cat) { $breadcrumbs->addCrumb($cat->getId(), ['label' => $cat->getName(), 'title' => $cat->getName(), 'link' => $cat->getUrl()]); } $breadcrumbs->addCrumb($category->getId(), ['label' => $category->getName(), 'title' => $category->getName()]); } } return $this; }
/** * @return $this * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function _prepareLayout() { parent::_prepareLayout(); $title = $metaTitle = __("Search results for: '%1'", $this->getRequest()->getParam('q')); $metaDescription = $this->config->getBaseMetaDescription(); $metaKeywords = $this->config->getBaseMetaKeywords(); $this->pageConfig->getTitle()->set($metaTitle); $this->pageConfig->setDescription($metaDescription); $this->pageConfig->setKeywords($metaKeywords); /** @var \Magento\Theme\Block\Html\Title $pageMainTitle */ $pageMainTitle = $this->getLayout()->getBlock('page.main.title'); if ($pageMainTitle) { $pageMainTitle->setPageTitle($title); } /** @var \Magento\Theme\Block\Html\Breadcrumbs $breadcrumbs */ if ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) { $breadcrumbs->addCrumb('home', ['label' => __('Home'), 'title' => __('Go to Home Page'), 'link' => $this->context->getUrlBuilder()->getBaseUrl()])->addCrumb('blog', ['label' => $this->config->getBlogName(), 'title' => $this->config->getBlogName(), 'link' => $this->config->getBaseUrl()])->addCrumb('search', ['label' => $title, 'title' => $title]); } return $this; }
/** * {@inheritdoc} * * @param EventObserver $observer */ public function execute(EventObserver $observer) { /** @var \Magento\Framework\Data\Tree\Node $menu */ $menu = $observer->getData('menu'); $categories = $this->categoryCollectionFactory->create()->addAttributeToSelect(['name', 'url_key'])->excludeRoot()->addVisibilityFilter(); $tree = $categories->getTree(); $rootNode = new TreeNode(['id' => 'blog-node-root', 'name' => $this->config->getMenuTitle(), 'url' => $this->config->getBaseUrl()], 'id', $menu->getTree(), null); $menu->addChild($rootNode); foreach ($tree as $category) { if (isset($tree[$category->getParentId()])) { $parentNode = $tree[$category->getParentId()]->getData('node'); } else { $parentNode = $rootNode; } $node = new TreeNode(['id' => 'blog-node-' . $category->getId(), 'name' => $category->getName(), 'url' => $category->getUrl()], 'id', $menu->getTree(), $parentNode); if ($parentNode) { $parentNode->addChild($node); } else { $menu->addChild($node); } $category->setData('node', $node); } }