Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a view with a page which has an exposed filed on taxonomy terms with the "Remember the last selection" enabled. The view has the "Exposed form in block" option enabled. It works if the block is displayed on the same page, but not if the block is displayed on another page.
Comment | File | Size | Author |
---|---|---|---|
#6 | 2551431-5.patch | 8.11 KB | dawehner |
Comments
Comment #2
Lukas von BlarerIn case this helps, here is the exported view:
Comment #3
dawehnerThank you for your great bug report!
I have some feeling that this is yet another cacheability issue. Did you tried to disable caching for the exposed form block?
I think we need to expand somehow the way how we render exposed forms to include the session cache context in case the view is configured to remember the value.
Comment #4
Lukas von BlarerNo, caching is disabled on this block.
Comment #5
Lukas von BlarerAh and I also disabled caching on the view itself. Could it be that the exposed filters are only safed for the corresponding path of the views page?
Comment #6
dawehnerAlright, so we need the session value being part of the actual views cache context.
Comment #7
Wim LeersI don't think we want an additional cache context; I think the existing
session
(\Drupal\Core\Cache\Context\SessionCacheContext
) cache context can be updated to implementCalculatedCacheContextInterface
, just like\Drupal\Core\Cache\Context\QueryArgsCacheContext
already does for example.That'll then allow you to write
session:some_key
.Just to make sure I understand: this change — and many like it — are not necessary strictly speaking, but they're just clean-up, right?
Comment #8
dawehnerWell, if we want to be able to use
$request->getSession()->get()
this would be needed.Comment #9
Lukas von BlarerThe patch did not fix the issue for me. The filters are applied, but when visiting the form again the default values are not being set. Is there anything I could do to help debug this?
Comment #11
alexej_d CreditAttribution: alexej_d commentedI can confirm that this bug still exists. It is obviously connected with the caching system. My views page does remember the settings of exposed filters but once caching is on the exposed filter persists till the next cache clearing which renders this function unusable with cache…
Comment #12
alexej_d CreditAttribution: alexej_d commentedI also noticed a different problem: ViewExecutable.php has this line
which is pretty fragile. When "remember the last selection" was active and I tried to fetch a view with a _format parameter in the url, the exposed filter would unset itself…
Comment #13
dawehnerOH yeah, can't agree more. Do you have a general idea how to deal with that?
Comment #14
alexej_d CreditAttribution: alexej_d commentedMaybe each view with exposed forms has to store a list of applicable parameters. When you define a new exposed filter the list is updated. On request only parameters from this list are being considered. But I have no idea what the performance implications would be and I think at this stage it is too late to implement such a change…
Comment #15
legolasboThis is probably a duplicate of #2596649: Exposed form does not save state when it is placed in a block, because at the exposed filter block does not provide any cacheability metadata, which it should do.
Comment #27
smustgrave CreditAttribution: smustgrave at Mobomo commentedSo I tested by
Created a taxonomy page view
Added a filter by name checking if value contains and checking Remember last selection
Exposed the form block to yes
Placed the block on a random page and my view page
The search feature works on both (though on the random page it redirects me to the view page when I search)
Neither seem to "Remember my selection"
Interesting when I turn off exposed form block and go to the view page it doesn't remember my selection then either.
Not sure if I'm testing that right but any feedback would be appreciated.