Search.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\Sidebar;
  9. /**
  10. * Blog sidebar categories block
  11. */
  12. class Search extends \Magento\Framework\View\Element\Template
  13. {
  14. use Widget;
  15. /**
  16. * @var \Magefan\Blog\Model\Url
  17. */
  18. protected $_url;
  19. /**
  20. * Construct
  21. *
  22. * @param \Magento\Framework\View\Element\Context $context
  23. * @param \Magefan\Blog\Model\Url $url
  24. * @param array $data
  25. */
  26. public function __construct(
  27. \Magento\Framework\View\Element\Template\Context $context,
  28. \Magefan\Blog\Model\Url $url,
  29. array $data = []
  30. ) {
  31. parent::__construct($context, $data);
  32. $this->_url = $url;
  33. }
  34. /**
  35. * @var string
  36. */
  37. protected $_widgetKey = 'search';
  38. /**
  39. * Retrieve query
  40. * @return string
  41. */
  42. public function getQuery()
  43. {
  44. return urldecode($this->getRequest()->getParam('q', ''));
  45. }
  46. /**
  47. * Retrieve serch form action url
  48. * @return string
  49. */
  50. public function getFormUrl()
  51. {
  52. return $this->_url->getUrl('', \Magefan\Blog\Model\Url::CONTROLLER_SEARCH);
  53. }
  54. }