123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- /**
- * Copyright © 2016 Ihor Vansach (ihor@magefan.com). All rights reserved.
- * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
- *
- * Glory to Ukraine! Glory to the heroes!
- */
- namespace Magefan\Blog\Block\Post;
- use Magento\Store\Model\ScopeInterface;
- /**
- * Blog post list block
- */
- class PostList extends \Magefan\Blog\Block\Post\PostList\AbstractList
- {
- /**
- * Block template file
- * @var string
- */
- protected $_defaultToolbarBlock = 'Magefan\Blog\Block\Post\PostList\Toolbar';
- /**
- * Preparing global layout
- *
- * @return $this
- */
- protected function _prepareLayout()
- {
- $page = $this->_request->getParam(
- \Magefan\Blog\Block\Post\PostList\Toolbar::PAGE_PARM_NAME
- );
- if ($page > 1) {
- $this->pageConfig->setRobots('NOINDEX,FOLLOW');
- }
- return parent::_prepareLayout();
- }
- /**
- * Retrieve post html
- * @param \Magefan\Blog\Model\Post $post
- * @return string
- */
- public function getPostHtml($post)
- {
- return $this->getChildBlock('blog.posts.list.item')->setPost($post)->toHtml();
- }
- /**
- * Retrieve Toolbar Block
- * @return \Magefan\Blog\Block\Post\PostList\Toolbar
- */
- public function getToolbarBlock()
- {
- $blockName = $this->getToolbarBlockName();
- if ($blockName) {
- $block = $this->getLayout()->getBlock($blockName);
- if ($block) {
- return $block;
- }
- }
- $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, uniqid(microtime()));
- return $block;
- }
- /**
- * Retrieve Toolbar Html
- * @return string
- */
- public function getToolbarHtml()
- {
- return $this->getChildHtml('toolbar');
- }
- /**
- * Before block to html
- *
- * @return $this
- */
- protected function _beforeToHtml()
- {
- $toolbar = $this->getToolbarBlock();
- // called prepare sortable parameters
- $collection = $this->getPostCollection();
- // set collection to toolbar and apply sort
- $toolbar->setCollection($collection);
- $this->setChild('toolbar', $toolbar);
- return parent::_beforeToHtml();
- }
- /**
- * Prepare breadcrumbs
- *
- * @param string $title
- * @param string $key
- * @throws \Magento\Framework\Exception\LocalizedException
- * @return void
- */
- protected function _addBreadcrumbs($title = null, $key = null)
- {
- if ($breadcrumbsBlock = $this->getBreadcrumbsBlock()) {
- $breadcrumbsBlock->addCrumb(
- 'home',
- [
- 'label' => __('Home'),
- 'title' => __('Go to Home Page'),
- 'link' => $this->_storeManager->getStore()->getBaseUrl()
- ]
- );
- $blogTitle = $this->_scopeConfig->getValue(
- 'mfblog/index_page/title',
- ScopeInterface::SCOPE_STORE
- );
- $breadcrumbsBlock->addCrumb(
- 'blog',
- [
- 'label' => __($blogTitle),
- 'title' => __($blogTitle),
- 'link' => $title ? $this->_url->getBaseUrl() : null,
- ]
- );
- if ($title) {
- $breadcrumbsBlock->addCrumb($key ?: 'blog_item', ['label' => $title, 'title' => $title]);
- }
- }
- }
- /**
- * Retrieve breadcrumbs block
- *
- * @return mixed
- */
- protected function getBreadcrumbsBlock()
- {
- if ($this->_scopeConfig->getValue('web/default/show_cms_breadcrumbs', ScopeInterface::SCOPE_STORE)) {
- return $this->getLayout()->getBlock('breadcrumbs');
- }
- return false;
- }
- }
|