Example #1
0
 /**
  * @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;
 }
Example #2
0
 /**
  * @return string
  */
 protected function getOrderField()
 {
     if ($this->orderField === null) {
         $this->orderField = $this->config->getDefaultSortField();
     }
     return $this->orderField;
 }
Example #3
0
 /**
  * @param string $fileName
  * @return void
  */
 private function deleteImage($fileName)
 {
     $path = $this->config->getMediaPath();
     if ($fileName && file_exists($path . '/' . $fileName)) {
         unlink($path . '/' . $fileName);
     }
     return;
 }
Example #4
0
 /**
  * {@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);
     }
 }
Example #5
0
 /**
  * Return url without suffix
  *
  * @param string $key
  * @return string
  */
 protected function trimSuffix($key)
 {
     $suffix = $this->config->getCategoryUrlSuffix();
     //user can enter .html or html suffix
     if ($suffix != '' && $suffix[0] != '.') {
         $suffix = '.' . $suffix;
     }
     $key = str_replace($suffix, '', $key);
     $suffix = $this->config->getPostUrlSuffix();
     //user can enter .html or html suffix
     if ($suffix != '' && $suffix[0] != '.') {
         $suffix = '.' . $suffix;
     }
     $key = str_replace($suffix, '', $key);
     return $key;
 }
Example #6
0
 /**
  * @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;
 }
Example #7
0
 /**
  * @return string
  */
 public function getFeaturedImageUrl()
 {
     return $this->config->getMediaUrl($this->getFeaturedImage());
 }