PostList.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Copyright © 2016 Ihor Vansach (ihor@magefan.com). All rights reserved.
  4. * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
  5. *
  6. * Glory to Ukraine! Glory to the heroes!
  7. */
  8. namespace Magefan\Blog\Block\Author;
  9. use Magento\Store\Model\ScopeInterface;
  10. /**
  11. * Blog author posts list
  12. */
  13. class PostList extends \Magefan\Blog\Block\Post\PostList
  14. {
  15. /**
  16. * Prepare posts collection
  17. *
  18. * @return void
  19. */
  20. protected function _preparePostCollection()
  21. {
  22. parent::_preparePostCollection();
  23. if ($author = $this->getAuthor()) {
  24. $this->_postCollection->addAuthorFilter($author);
  25. }
  26. }
  27. /**
  28. * Retrieve author instance
  29. *
  30. * @return \Magefan\Blog\Model\Author
  31. */
  32. public function getAuthor()
  33. {
  34. return $this->_coreRegistry->registry('current_blog_author');
  35. }
  36. /**
  37. * Preparing global layout
  38. *
  39. * @return $this
  40. */
  41. protected function _prepareLayout()
  42. {
  43. if ($author = $this->getAuthor()) {
  44. $this->_addBreadcrumbs($author->getTitle(), 'blog_author');
  45. $this->pageConfig->addBodyClass('blog-author-' . $author->getIdentifier());
  46. $this->pageConfig->getTitle()->set($author->getTitle());
  47. $this->pageConfig->addRemotePageAsset(
  48. $author->getAuthorUrl(),
  49. 'canonical',
  50. ['attributes' => ['rel' => 'canonical']]
  51. );
  52. $this->pageConfig->setRobots('NOINDEX,FOLLOW');
  53. }
  54. return parent::_prepareLayout();
  55. }
  56. }