From 715c3c3584df614deef6b3e05594769a610e8b98 Mon Sep 17 00:00:00 2001 From: Ilan Parmentier Date: Fri, 8 Mar 2019 14:44:20 +0100 Subject: [PATCH] Proper title and breadcrumbs Have a proper title and breadcrumbs for result page --- Block/Page/Result.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Block/Page/Result.php b/Block/Page/Result.php index f0fae0b..750827f 100644 --- a/Block/Page/Result.php +++ b/Block/Page/Result.php @@ -65,6 +65,34 @@ public function __construct( $this->cmsPage = $cmsPage; } + /** + * Prepare layout + * + * @return $this + */ + protected function _prepareLayout() + { + $title = $this->getSearchQueryText(); + $this->pageConfig->getTitle()->set($title); + // add Home breadcrumb + $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'); + if ($breadcrumbs) { + $breadcrumbs->addCrumb( + 'home', + [ + 'label' => __('Home'), + 'title' => __('Go to Home Page'), + 'link' => $this->_storeManager->getStore()->getBaseUrl() + ] + )->addCrumb( + 'search', + ['label' => $title, 'title' => $title] + ); + } + + return parent::_prepareLayout(); + } + /** * Returns cms page collection. * @@ -117,6 +145,16 @@ public function getPageUrl($pageId) return $this->cmsPage->getPageUrl($pageId); } + /** + * Get search query text + * + * @return \Magento\Framework\Phrase + */ + public function getSearchQueryText() + { + return __("Search results for: '%1'", $this->escapeHtml($this->getQueryText())); + } + /** * Init cms page collection. *