-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
A lot of the blocks have methods that return relative URLs.
Let's take for example the advanced search block Magento\CatalogSearch\Block\Advanced\Form
.
There is this method
public function getSearchPostUrl()
{
return $this->getUrl('*/*/result');
}
This means that the submit url for the search form (that by the way is submited via GET and the method is called getSearchPostUrl ) is {current_module_key}/{current_controller}/result
.
This means I cannot include this block in a custom cms page or block like this:
{{block type="Magento\CatalogSearch\Block\Advanced\Form" template="Magento_CatalogSearch::advanced/form.phtml"}}
Because I'm on a cms page the module key and controller won't match the advanced search ones.
I have to either create my own block that extends Magento\CatalogSearch\Block\Advanced\Form
and changes the getSearchPostUrl
and use that one, or I have to clone the template and change the form action.
The solutions I'm thinking of are:
- Simple and fast: You can change the block method to return
$this->getUrl('catalogsearch/advanced/result')
- The flexible one, allow dynamic values for urls.
public function getSearchPostUrl()
{
if ($url = $this->getData('search_post_url')) {
return $this->getUrl($url);
}
return $this->getUrl('*/*/result');
}
This will allow developers to do something like this:
{{block type="Magento\CatalogSearch\Block\Advanced\Form" template="Magento_CatalogSearch::advanced/form.phtml" search_post_url="catalogsearch/advanced/result" }}
This may not be the only case, but it's the first I found.