/** * @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; }
/** * @return \Gemtoo\Blog\Model\Article */ protected function initArticle() { $articleId = (int) $this->getRequest()->getParam('article_id'); $article = $this->articleFactory->create(); if ($articleId) { $article->load($articleId); } $this->coreRegistry->register('gemtoo_blog_article', $article); return $article; }
/** * prepare collection * @return $this */ protected function _prepareCollection() { $collection = $this->articleCollectionFactory->create(); if ($this->getCategory()->getId()) { $constraint = 'related.category_id=' . $this->getCategory()->getId(); } else { $constraint = 'related.category_id=0'; } $collection->getSelect()->joinLeft(['related' => $collection->getTable('gemtoo_blog_article_category')], 'related.article_id=main_table.article_id AND ' . $constraint, ['position']); $this->setCollection($collection); return parent::_prepareCollection(); }
/** * @access public * @param \Magento\Catalog\Model\Product $product * @return \Gemtoo\Blog\Model\ResourceModel\Article\Collection */ public function getSelectedArticlesCollection(ProductModel $product) { $collection = $this->articleCollectionFactory->create()->addProductFilter($product); return $collection; }
/** * @access public * @param \Magento\Catalog\Model\Category $category * @return \Gemtoo\Blog\Model\ResourceModel\Article\Collection */ public function getSelectedArticlesCollection(CategoryModel $category) { $collection = $this->articleCollectionFactory->create()->addCategoryFilter($category); return $collection; }