Skip to content

Commit 978362c

Browse files
author
Ilan Parmentier
authored
Add breadcrumb, title
Adding a proper meta title, page heading to the page. Also, we do not forget to add a breadcrumb navigation.
1 parent ac0a973 commit 978362c

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Block/Post/Result.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,66 @@ public function __construct(
3939
$this->postCollection = $this->initPostCollection($postCollectionFactory);
4040
}
4141

42+
/**
43+
* Prepare layout
44+
*
45+
* @return $this
46+
*/
47+
protected function _prepareLayout()
48+
{
49+
$title = $this->getSearchQueryText();
50+
$this->pageConfig->getTitle()->set($title);
51+
52+
// add Home breadcrumb
53+
$breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
54+
if ($breadcrumbs) {
55+
$breadcrumbs->addCrumb(
56+
'home',
57+
[
58+
'label' => __('Home'),
59+
'title' => __('Go to Home Page'),
60+
'link' => $this->_storeManager->getStore()->getBaseUrl()
61+
]
62+
)->addCrumb(
63+
'search',
64+
[
65+
'label' => $title,
66+
'title' => $title,
67+
'link' => $this->getSearchUrl()
68+
]
69+
)->addCrumb(
70+
'blog_search',
71+
[
72+
'label' => __('Results in blog posts.'),
73+
'title' => __('Results in blog posts.')
74+
]
75+
);
76+
}
77+
78+
return parent::_prepareLayout();
79+
}
80+
81+
/**
82+
* Get search query text
83+
*
84+
* @return \Magento\Framework\Phrase
85+
*/
86+
public function getSearchQueryText()
87+
{
88+
return __("Search results for: '%1'", $this->escapeHtml($this->getQueryText()));
89+
}
90+
91+
/**
92+
* Returns catalog search url.
93+
*
94+
* @return string
95+
*/
96+
public function getSearchUrl()
97+
{
98+
$params = [QueryFactory::QUERY_VAR_NAME => $this->getQueryText()];
99+
return $this->getUrl('catalogsearch/result', ['_query' => $params]);
100+
}
101+
42102
/**
43103
* Returns blog bost collection.
44104
*

0 commit comments

Comments
 (0)