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.
Problem/Motivation
Steps to reproduce:
1. Create a view using a user contextual filter. Set the user contextual filter up to fall back to the current user.
2. Check the exported views YAML and see it has the route cache context.
This is because ArgumentPluginBase always adds the url cache context.
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
$contexts = [];
// By definition arguments depends on the URL.
// @todo Once contexts are properly injected into block views we could pull
// the information from there.
$contexts[] = 'url';
// Asks all subplugins (argument defaults, argument validator and styles).
if (($plugin = $this->getPlugin('argument_default')) && $plugin instanceof CacheableDependencyInterface) {
$contexts = Cache::mergeContexts($contexts, $plugin->getCacheContexts());
}
Proposed resolution
No idea, but if we had a way to specify that the argument is always going to come from the request and never from the URL it might be possible to skip this. Maybe a dedicated User-from-request argument implementing a different interface or something and this overrides that method to not add the URL cache context.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#10 | views-argument-option-no-url-cache-context-d10-2-x-3092715-10.patch | 2.3 KB | Gobind Singh |
#6 | views-argument-option-no-url-cache-context--3092715-1.patch | 2.55 KB | douggreen |
Comments
Comment #6
douggreen CreditAttribution: douggreen commentedWe could just add a views argument option and let the site builder decide. Patch attached.
Comment #10
Gobind Singh CreditAttribution: Gobind Singh at Everything Connected commentedRe-rolled for 10.2.x https://www.drupal.org/files/issues/2023-12-22/views-argument-option-no-...