Problem/Motivation
Core has 2 PageDisplayVariant plugins, those 2 plugins does not inject the cacheable metadata into the returned build array.
In app/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php, the PageDisplayVariantSelectionEvent event are injected into the plugin instance:
// Instantiate the page display, and give it the main content.
$page_display = $this->displayVariantManager->createInstance($variant_id, $variant_configuration);
...
$page_display
...
->addCacheableDependency($event);
But then in core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php and core/lib/Drupal/Core/Render/Plugin/DisplayVariant/SimplePageVariant.php there is no usage of those cache metadata in the build method.
Steps to reproduce
In the related issue we witnessed the problem when needing to inject a cache tag in the event for cache invalidation.
Proposed resolution
Inject cache metadata in the build method.
Remaining tasks
Provide MR
Provide test
Issue fork drupal-3557014
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3557014-pagedisplayvariant-does-not
changes, plain diff MR !13740
Comments
Comment #3
grimreaperComment #4
grimreaperComment #5
grimreaperComment #6
grimreaperComment #7
grimreaperComment #8
fathershawnThe code is consistent with
CacheableMetadatamanagement. The variant plugins implementCacheableMetadataInterfaceso it follows that their own metadata should be collected.Comment #9
catchCommitted/pushed to 11.x and cherry-picked to 11.3.x, thanks!