_categoryFactory = $categoryFactory; } /** * Set blog template * * @return this */ public function _toHtml() { $this->setTemplate( $this->getData('custom_template') ?: 'widget/recent.phtml' ); return parent::_toHtml(); } /** * Retrieve block title * * @return string */ public function getTitle() { return $this->getData('title') ?: __('Recent Blog Posts'); } /** * Prepare posts collection * * @return void */ protected function _preparePostCollection() { $size = $this->getData('number_of_posts'); if (!$size) { $size = (int) $this->_scopeConfig->getValue( 'mfblog/sidebar/recent_posts/posts_per_page', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } $this->setPageSize($size); parent::_preparePostCollection(); if ($category = $this->getCategory()) { $this->_postCollection->addCategoryFilter($category); } } /** * Retrieve category instance * * @return \Magefan\Blog\Model\Category */ public function getCategory() { if ($this->_category === null) { if ($categoryId = $this->getData('category_id')) { $category = $this->_categoryFactory->create(); $category->load($categoryId); $storeId = $this->_storeManager->getStore()->getId(); if ($category->isVisibleOnStore($storeId)) { $category->setStoreId($storeId); return $this->_category = $category; } } $this->_category = false; } return $this->_category; } /** * Retrieve post short content * @param \Magefan\Blog\Model\Post $post * * @return string */ public function getShorContent($post) { return $post->getShortFilteredContent(); } }