PostList.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\Search;
  9. use Magento\Store\Model\ScopeInterface;
  10. /**
  11. * Blog search result block
  12. */
  13. class PostList extends \Magefan\Blog\Block\Post\PostList
  14. {
  15. /**
  16. * Retrieve query
  17. * @return string
  18. */
  19. public function getQuery()
  20. {
  21. return urldecode($this->getRequest()->getParam('q'));
  22. }
  23. /**
  24. * Prepare posts collection
  25. *
  26. * @return void
  27. */
  28. protected function _preparePostCollection()
  29. {
  30. parent::_preparePostCollection();
  31. $this->_postCollection->addSearchFilter(
  32. $this->getQuery()
  33. );
  34. }
  35. /**
  36. * Preparing global layout
  37. *
  38. * @return $this
  39. */
  40. protected function _prepareLayout()
  41. {
  42. $title = $this->_getTitle();
  43. $this->_addBreadcrumbs($title, 'blog_search');
  44. $this->pageConfig->getTitle()->set($title);
  45. $this->pageConfig->setRobots('NOINDEX,FOLLOW');
  46. return parent::_prepareLayout();
  47. }
  48. /**
  49. * Retrieve title
  50. * @return string
  51. */
  52. protected function _getTitle()
  53. {
  54. return __('Search "%1"', $this->getQuery());
  55. }
  56. }