richardhj / contao-ajax_reload_element

AjaxReloadElement for Contao Open Source CMS
GNU Lesser General Public License v3.0
14 stars 5 forks source link

Fix error on index page #25

Closed fritzmg closed 2 years ago

fritzmg commented 2 years ago

There is an error if you try to load an element or module on the start page (index). In this case Environment::get('request') will return an empty string or something like

?page_n2=2

in case of a newslist pagination for example. Running that through the ContaoCommunityAlliance\UrlBuilder\UrlBuilder will then however give you the following URL:

page_n2=2

This is of course wrong - and this wrong request URL will then be set in the Environment - which will break any URLs generated by Contao. To work around this bug, this PR simply prepends the request URL with a slash - and then removes it again, since the Environment class assumes it to be without the leading slash (contrary to Symfony's Request).

See also https://github.com/contao-community-alliance/url-builder/issues/3

richardhj commented 2 years ago

I think if there is a way to remove the dependency on cca/url-builder, that's also great. However, this solution looks appropriate.

fritzmg commented 2 years ago

May be this can be removed in general?

https://github.com/richardhj/contao-ajax_reload_element/blob/b315d8d4e59b82ea472c7301152fed925118a756/src/EventListener/AjaxReloadElementListener.php#L106-L112

Your example in the README uses a POST request anyway to set the ajax_reload_element parameter. So it would not be present as a GET parameter in the first place. And I am not sure why it would need to be removed from the request in general, shouldn't really matter in the end?