ext-solr icon indicating copy to clipboard operation
ext-solr copied to clipboard

`BeforeSearchFormIsShownEvent` is immutable

Open ghost opened this issue 1 year ago • 3 comments

The BeforeSearchFormIsShownEvent is currently immutable. It has no setters or public variables whatsoever. This makes it pretty useless.

I wanted to inject some variables into the Search Form Template using this event, then found out that the event object can not be altered. An event should allow to actually alter or atleast add some variables when the event is fired.

ext:solr v12, TYPO3 v12, PHP v8.3.

ghost avatar Nov 06 '24 10:11 ghost

Sometimes it is important to disallow the changes/side-effects, but allow the information retrieval. Which property do you want to override?

Edit: IMHO additionalFilters only is relevant for changes.

dkd-kaehm avatar Nov 06 '24 11:11 dkd-kaehm

Edit: IMHO additionalFilters only is relevant for changes.

But this is immutable as well. I expected this event to provide the possibility to add (new, additional) template variables (which I then can use in my overridden Fluid template). I now created an extra ViewHelper to fetch it from inside the Search Form Template (which I see as spaghetti, beause Fluid Templates should not have any fetch logic, but get all stuff passed pre-calculated into).

ghost avatar Nov 08 '24 10:11 ghost

Edit: IMHO additionalFilters only is relevant for changes.

But this is immutable as well. I expected this event to provide the possibility to add (new, additional) template variables (which I then can use in my overridden Fluid template). I now created an extra ViewHelper to fetch it from inside the Search Form Template (which I see as spaghetti, beause Fluid Templates should not have any fetch logic, but get all stuff passed pre-calculated into).

Please provide your suggestion as pull-request.

dkd-kaehm avatar Nov 08 '24 12:11 dkd-kaehm

I have the same issue. I would like to provide the q parameter as it is not available in the search form. Before i could use the hook slot by using this code:

<?php

namespace Vendor\Extension\Slot;

class SearchFormSlot
{
    public function addQueryStringToForm(array $values): array
    {
        $request = $GLOBALS['TYPO3_REQUEST'];
        $queryParams = $request->getQueryParams();
        $values['q'] = $queryParams['tx_solr']['q'] ?? null;

        return [$values];
    }
}

Now I'm not able to replace this code with the event as I can't set any values.

What would be really helpful would be the same functionality like here: #3915

simonschaufi avatar Nov 26 '25 14:11 simonschaufi