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
Comments
Comment #6
douggreen commentedWe could just add a views argument option and let the site builder decide. Patch attached.
Comment #10
gobind singh commentedRe-rolled for 10.2.x https://www.drupal.org/files/issues/2023-12-22/views-argument-option-no-...