Exemple #1
0
 /**
  * @return \Magento\Framework\Controller\Result\Forward|\Magento\Framework\View\Result\Page
  */
 public function execute()
 {
     $articleId = (int) $this->getRequest()->getParam('id');
     $article = $this->articleFactory->create();
     $article->load($articleId);
     if (!$article->isActive()) {
         $resultForward = $this->resultForwardFactory->create();
         $resultForward->forward('noroute');
         return $resultForward;
     }
     $this->coreRegistry->register('current_article', $article);
     $resultPage = $this->resultPageFactory->create();
     $title = $article->getMetaTitle() ?: $article->getName();
     $resultPage->getConfig()->getTitle()->set($title);
     $resultPage->getConfig()->setDescription($article->getMetaDescription());
     $resultPage->getConfig()->setKeywords($article->getMetaKeywords());
     if ($this->scopeConfig->isSetFlag(self::BREADCRUMBS_CONFIG_PATH, ScopeInterface::SCOPE_STORE)) {
         /** @var \Magento\Theme\Block\Html\Breadcrumbs $breadcrumbsBlock */
         $breadcrumbsBlock = $resultPage->getLayout()->getBlock('breadcrumbs');
         if ($breadcrumbsBlock) {
             $breadcrumbsBlock->addCrumb('home', ['label' => __('Home'), 'link' => $this->_url->getUrl('')]);
             $breadcrumbsBlock->addCrumb('articles', ['label' => __('Articles'), 'link' => $this->urlModel->getListUrl()]);
             $breadcrumbsBlock->addCrumb('article-' . $article->getId(), ['label' => $article->getName()]);
         }
     }
     return $resultPage;
 }
Exemple #2
0
 /**
  * @param $observer
  * @return $this
  */
 public function execute(EventObserver $observer)
 {
     $menu = $observer->getMenu();
     $tree = $menu->getTree();
     $fullAction = $this->request->getFullActionName();
     $selectedActions = ['gemtoo_blog_article_index', 'gemtoo_blog_article_view'];
     $articleNodeId = 'articles';
     $data = ['name' => __('Blog'), 'id' => $articleNodeId, 'url' => $this->articleUrl->getListUrl(), 'is_active' => in_array($fullAction, $selectedActions)];
     $articlesNode = new Node($data, 'id', $tree, $menu);
     $menu->addChild($articlesNode);
     return $this;
 }
Exemple #3
0
 /**
  * @return array
  */
 public function getRssData()
 {
     $url = $this->urlModel->getListUrl();
     $data = ['title' => __('Articles'), 'description' => __('Articles'), 'link' => $url, 'charset' => 'UTF-8'];
     $collection = $this->articleCollectionFactory->create();
     $collection->addStoreFilter($this->getStoreId());
     $collection->addFieldToFilter('is_active', 1);
     //TODO: use constant
     $collection->addFieldToFilter('in_rss', 1);
     //TODO: use constant
     foreach ($collection as $item) {
         /** @var \Gemtoo\Blog\Model\Article $item */
         //TODO: add more attributes to RSS
         $description = '<table><tr><td><a href="%s">%s</a></td></tr></table>';
         $description = sprintf($description, $item->getArticleUrl(), $item->getName());
         $data['entries'][] = ['title' => $item->getName(), 'link' => $item->getArticleUrl(), 'description' => $description];
     }
     return $data;
 }
Exemple #4
0
 /**
  * @return mixed
  */
 public function getArticleUrl()
 {
     return $this->urlModel->getArticleUrl($this);
 }