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
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';
Currently, adding an argument to a view makes the view cacheable per url even if the argument value depends only on a single query argument value.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#42 | 2514784-42.patch | 7.38 KB | malcolm_p |
#24 | 2514784-23.patch | 2.7 KB | mparker17 |
Comments
Comment #1
olli CreditAttribution: olli commentedComment #2
olli CreditAttribution: olli commentedComment #3
dawehnerYeah right, ideally for blocks this is not true, but for now, this is the best thing we can do.
Do you mind adding a test coverage for that?
Comment #5
lauriiiThe test failures seems to be related to changed cache contexts. We should also remove the comment and @todo. Also manual testing would be good.
Comment #6
Wim LeersComment #7
olli CreditAttribution: olli commented- Fixed test failures
- Removed the comment and @todo
Manually tested
1. Installed standard with latest head
2. Created article with a tag
3. Visited taxonomy/term/1 and checked that X-Drupal-Cache-Contexts header included 'url'
4. Re-saved taxonomy_term view
5. Visited taxonomy/term/1 and checked that X-Drupal-Cache-Contexts header didn't include 'url' but 'url.query_args.pagers:0'
Do we also need a hook_update_N() here that saves all views?
Comment #8
jibranI think so yeah. Not all though just the one using arguments.
Comment #9
jibranGoing to write an update hook.
Comment #10
olli CreditAttribution: olli commentedHere's views_update_8001(). I think we also need to update existing views using arguments.
Comment #11
olli CreditAttribution: olli commented#9: Great! I hope #10 helps.. Manually tested that and it seemed to work.
Comment #12
jibranWow nice x-post. Needs update hook test now. interdiff is against 7.
Comment #13
olli CreditAttribution: olli commentedWhy only enabled?
#12 seems to work but I got "mb_strtolower() expects parameter 1 to be string, array given Unicode.php:331" with drush updb.
Comment #14
jibranOh yeah we can remove the enable check. Nice catch.
Maybe mb_strtolower() error is because the value of
display.*.display_options.arguments.*
is an array not string.Feel free to work on this. You can copy the
\Drupal\system\Tests\Update\UpdateSchemaTest
to test the hook. If you want to carry on with your patch that's fine by me as well.Comment #16
jibranComment #17
jibranI recreated the patch. If we'll get this in before #2464427: Replace CacheablePluginInterface with CacheableDependencyInterface then we don't need an update hook. There are is a test fix so we already have tests for this. No interdiff because I re-created it.
Comment #18
Wim LeersWhy would we not need an update hook if we get this in first? Views config entities in HEAD already have cacheability metadata stored/exported.
Comment #19
dawehnerWell, we would have to resave the cache contexts of the view, so its reflected before rendering for the query.
Comment #20
olli CreditAttribution: olli commentedComment #23
mparker17Re-rolled the patch in #17. There was a merge conflict in
core/modules/views/src/Tests/Plugin/DisplayPageWebTest.php
:... which I resolved to...
Comment #24
mparker17I should probably upload that re-rolled patch...
Comment #25
dawehnerPuh, this could break existing code out there which maybe relies on it?
Comment #33
malcolm_p CreditAttribution: malcolm_p commentedI've rerolled this for 8.5.x, were there any outstanding issues blocking this and the linked QueryParameter patch from making it into core? It seems like all of the argument related views plugins are now setting their own cache contexts.
Comment #34
dawehnerComment #36
catchComment #39
malcolm_p CreditAttribution: malcolm_p commentedRe-roll for 8.9.x.
Comment #41
malcolm_p CreditAttribution: malcolm_p commentedOne more patch with updated configs for
Drupal\KernelTests\Config\DefaultConfigTest::testModuleConfig
and adding a hook_post_update based on #12.Comment #42
malcolm_p CreditAttribution: malcolm_p commentedAnd once more to fix the deprecation in the post_update hook.
Comment #48
DieterHolvoet CreditAttribution: DieterHolvoet at Minsky commentedComment #49
smustgrave CreditAttribution: smustgrave at Mobomo commentedLast patch seems for 8.9?