Proposed commit message:

Issue #2474121 by pwolanin, Wim Leers: CacheableMetadata should get BubbleableMetadata's merge/applyTo/createFromRenderArray/createFromObject methods

Necessary for #2335661: Outbound path & route processors must specify cacheability metadata, and sensible for symmetry.

Please credit pwolanin, who did most of the work on this patch in #2335661: Outbound path & route processors must specify cacheability metadata, this was just split off to a different issue to keep the other one focused.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task, because it is a simple task.
Issue priority Normal, because the task in itself is normal, however a critical issue depends on it.
Prioritized changes The main goal of this issue is to unblock work that promises correctness and more performance in the caching layer.
Disruption Not disruptive, because BubbleableMetadata keeps BC, only methods are moved.
CommentFileSizeAuthor
#5 interdiff.txt8.62 KBwim leers
#5 2474121-5.patch19.6 KBwim leers
#1 2474121-1.patch10.78 KBwim leers

Comments

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new10.78 KB
fabianx’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
fabianx’s picture

Reviewing #2099137: Entity/field access and node grants not taken into account with core cache contexts: That issue uses BubbleableMetadata needlessly when this patch goes in.

Should we convert usages of BubbleableMetadata that should have been CacheableMetadata here or in a follow-up?

wim leers’s picture

Status: Reviewed & tested by the community » Needs work

Let's do it here.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new19.6 KB
new8.62 KB

So, what #3 referred to is basically addressing @yched's #2099137-161: Entity/field access and node grants not taken into account with core cache contexts, point 7, which was out of scope to change there, but thanks to the changes here, we can now actually address that.

At the same time, we can update RendererInterface::addDependency() to use this.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC, the remaining usages of BubbleableMetadata want to deal with #post_render_cache or #attached ...

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This blocks a critical. Committed 149c25e and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary.

diff --git a/core/lib/Drupal/Core/Render/BubbleableMetadata.php b/core/lib/Drupal/Core/Render/BubbleableMetadata.php
index b231d0f..bed247a 100644
--- a/core/lib/Drupal/Core/Render/BubbleableMetadata.php
+++ b/core/lib/Drupal/Core/Render/BubbleableMetadata.php
@@ -8,8 +8,6 @@
 namespace Drupal\Core\Render;
 
 use Drupal\Component\Utility\NestedArray;
-use Drupal\Core\Cache\Cache;
-use Drupal\Core\Cache\CacheableDependencyInterface;
 use Drupal\Core\Cache\CacheableMetadata;
 
 /**
@@ -36,8 +34,9 @@ class BubbleableMetadata extends CacheableMetadata {
   /**
    * Merges the values of another bubbleable metadata object with this one.
    *
-   * @param \Drupal\Core\Render\CacheableMetadata $other
+   * @param \Drupal\Core\Cache\CacheableMetadata $other
    *   The other bubbleable metadata object.
+   *
    * @return static
    *   A new bubbleable metadata object, with the merged data.
    *

Fixed on commit.

  • alexpott committed 149c25e on 8.0.x
    Issue #2474121 by Wim Leers: CacheableMetadata should get...
wim leers’s picture

Thanks!

Rerolled the blocked issue, and noticed a small flaw/thing we missed in this patch. See #2335661-69: Outbound path & route processors must specify cacheability metadata.

fabianx’s picture

I think its worth doing a quick follow-up for that normal bug to add the instanceof so we don't forget independently of the other issue ...

  • alexpott committed 77f2abc on 8.0.x
    Issue #2475397 by Wim Leers: Tiny follow-up for #2474121 + unit test...

Status: Fixed » Closed (fixed)

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

yched’s picture

#2099137: Entity/field access and node grants not taken into account with core cache contexts had \Drupal\views\Plugin\views\field\Field::getItems() merge BubblebleMetadata from the formatter's render array wrapper (which Views doesn't render) into each of the children (which are the ones that get rendered)

This patch here changed that to merging CacheableMetadata instead, leaving out #attached. Meaning, formatters who include assets are broken in Views, unless they repeatedly #attach them to each item children.

I posted a patch in #2496039: Formatter's #attached assets are not carried over by Views before realizing this had been explicitly changed here, so feedback welcome :-)