12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?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\Archive;
- use Magento\Store\Model\ScopeInterface;
- /**
- * Blog archive posts list
- */
- class PostList extends \Magefan\Blog\Block\Post\PostList
- {
- /**
- * Prepare posts collection
- * @return \Magefan\Blog\Model\ResourceModel\Post\Collection
- */
- protected function _preparePostCollection()
- {
- parent::_preparePostCollection();
- $this->_postCollection->addArchiveFilter(
- $this->getYear(),
- $this->getMonth()
- );
- }
- /**
- * Get archive month
- * @return string
- */
- public function getMonth()
- {
- return (int)$this->_coreRegistry->registry('current_blog_archive_month');
- }
- /**
- * Get archive year
- * @return string
- */
- public function getYear()
- {
- return (int)$this->_coreRegistry->registry('current_blog_archive_year');
- }
- /**
- * Preparing global layout
- *
- * @return $this
- */
- protected function _prepareLayout()
- {
- $title = $this->_getTitle();
- $this->_addBreadcrumbs($title, 'blog_search');
- $this->pageConfig->getTitle()->set($title);
- $this->pageConfig->addRemotePageAsset(
- $this->_url->getUrl(
- $this->getYear() . '-' . str_pad($this->getMonth(), 2, '0', STR_PAD_LEFT),
- \Magefan\Blog\Model\Url::CONTROLLER_ARCHIVE
- ),
- 'canonical',
- ['attributes' => ['rel' => 'canonical']]
- );
- $this->pageConfig->setRobots('NOINDEX,FOLLOW');
- return parent::_prepareLayout();
- }
- /**
- * Retrieve title
- * @return string
- */
- protected function _getTitle()
- {
- $time = strtotime($this->getYear().'-'.$this->getMonth().'-01');
- return sprintf(
- __('Monthly Archives: %s %s'),
- __(date('F', $time)), date('Y', $time)
- );
- }
- }
|