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

Command icon 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:

Comments

grimreaper created an issue. See original summary.

grimreaper’s picture

Assigned: grimreaper » Unassigned
Issue summary: View changes
Status: Active » Needs work
grimreaper’s picture

Assigned: Unassigned » grimreaper
grimreaper’s picture

Status: Needs work » Needs review
Issue tags: +Contributed project blocker
grimreaper’s picture

Assigned: grimreaper » Unassigned
grimreaper’s picture

Issue summary: View changes
fathershawn’s picture

Status: Needs review » Reviewed & tested by the community

The code is consistent with CacheableMetadata management. The variant plugins implement CacheableMetadataInterface so it follows that their own metadata should be collected.

catch’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 11.3.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • catch committed 167d02bc on 11.3.x
    fix: #3557014 PageDisplayVariant does not transmit cache metadata
    
    By:...

  • catch committed 584cb6e7 on 11.x
    fix: #3557014 PageDisplayVariant does not transmit cache metadata
    
    By:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.