Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
render system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
15 Sep 2015 at 19:55 UTC
Updated:
10 Oct 2015 at 00:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
tim.plunkettComment #3
dsnopekThis looks perfect! Assuming the tests pass, this pretty much RTBC as far as I'm concerned. :-) I'll wait until we have a new patch for Page Manager on #2511570: Remove Drupal\page_manager\Plugin\PageAwareVariantInterface that uses this to actually mark RTBC.
Note: This is a blocker for Page Manager and Panels Everywhere!
This is very similar in nature to this other core issue #2550941: Allow passing contexts to display variants (to enable Panels Everywhere to use static context and relationships), but for contexts rather than cache metadata.
Comment #5
eclipsegc commentedYeah that really sucks... Should the calling code be responsible for this in some way?
This looks really great other then this one issue.
Eclipse
Comment #6
dsnopek@EclipseGC: I assume you're referring to this chunk?
So, it's a little weird that we're calling
CacheableMetadata::createFromRenderArray()because we know there's nothing on the render array yet (because we just created it).However, the rest of this is how it should be: it should be up to the variant to decide where to add the cacheable metadata that was passed to it. I could imagine variants where it would put it somewhere deeper in the render array, because maybe it's only the inner parts that are dependent on configuration and the outer parts are static (ie. not affected by changes to configuration).
(BTW, in practice I think we'll be setting at least
$build['#cache']['keys']before doingCacheableMetadata::createFromRenderArray($build)so it'll be less weird in real code.)Setting back to NR since it's the fail patch that put us in NW.
Comment #7
dsnopekUpdated the issue summary, but this still needs a BETA evaluation.
Comment #8
dsnopekAdded the beta evaluation.
Comment #11
wim leersAlternative:
Comment #12
wim leersThe
$eventcontains cacheability metadata? That seems impossible.Oh this is why it's possible.
It's to allow cacheability metadata involved in the selection of the page variant to be bubbled, then? That makes sense!
This does not get the cacheability metadata of the page variant instance though, right?
Comment #13
dsnopekAh, yeah, that is better! Here's a new patch that just makes this change.
Yep! In most cases, this will be passing the cacheability metadata from config entity that's the source of the configuration that's also being passed to the page variant.
Right. If the page variant has other cacheability metadata that it's aware of (for example, from contexts) then it'll add it to the render array itself.
Comment #14
wim leersBut … that's a distinctly different thing, isn't it?
The event is a value object that represents the end result of a selection process. That end result is a plugin ID (
simple,block,page_manager…). Therefore, the cacheability metadata on the event should only contain the cacheability metadata that led to that plugin ID being selected.The reason we haven't needed that thus far, is that the
simplepage variant is the default, and if theblockmodule is enabled, then theblockpage variant is selected, always. i.e., so far, there is zero conditionality; the selected page variant depends solely on the set of enabled modules (and installing new modules clears all caches). This is also why #2565887: Fix test failures stemming from Dynamic Page Cache was necessary to make Page Manager work once Dynamic Page Cache was committed: because it can be configured to override the used page variant on certain routes, it doesn't override all routes!Now… after that hopefully crystal clear explanation… it's totally possible that this is in fact exactly what is happening here, and therefore it is the same thing! That is, if it's the Panels/Page Manager/whatever config entity here that contains the data that tells the module whether a certain route should use a different page variant, then that config entity is the thing that affects the selection criteria.
So, my point is this: if the config entity is just something used by the page variant but not the thing that causes that page variant to be selected, then it would be wrong to add its cacheability metadata to the event value object.
Whew. Hope that made sense :)
Comment #15
dsnopekBut we also pass configuration to the variant in this event. So it would make sense to pass the cacheability metadata for that config here too, right?
Comment #16
dsnopekAnd if not here, then where?
Comment #20
xanoMUST all variants provide this metadata? If no, then the base interface should not extend
CacheableDependencyInterface.If yes, does external code really need to refine cacheability metadata directly? This looks like something the config setter methods should take care of internally. As a developer, I don't want to have call two separate methods to set config and to refine cacheability metadata.
Comment #21
dsnopekEffectively, yes.
If the configuration passed to
setConfiguration()came from CMI (which will be 99.99% of the time in Drupal 8), then cacheability metadata MUST be provided or the render array returned fromVariantInterface::build()will have incorrect cacheability metadata on it, namely, the cache won't be cleared when the configuration changes.Note: All config objects and entities from CMI have cacheability metadata on them, we just need to find a way to pass it to the variant.
No, the external code doesn't need to refine it directly. If we could pass it into
setConfiguration()that'd be awesome! But we're unfortunately stuck withConfigurablePluginInterfacewhich only takes the one argument. :-/If we add a 2nd argument, even if it's optional, that could cause problems with code that is designed to work generically with classes implementing
ConfigurablePluginInterfacewhich wouldn't know the special rules for dealing withVariantInterface. The same applies to adding a specialsetCacheableConfiguration()method. We discussed all of these options on the page_manager issue that spawned this: #2511570: Remove Drupal\page_manager\Plugin\PageAwareVariantInterface (see the comments near #62/#63)We couldn't come up with a better solution that didn't break BC. But if you have any ideas, they're definitely welcome! :-)
Comment #22
xanoThe plugin is the provider of its own configuration. You shouldn't set any configuration through
ConfigurablePluginInterfacethat you didn't first export through that same interface.That would be very far from awesome, as explained earlier. Do not ever mass-import any configuration that you did not mass-export earlier. If you want to change configuration, that must be done through separate, plugin-specific methods on the plugin instance itself.
To summarize: please stop thinking about
ConfigurablePluginInterface. It's not for what you are trying to achieve. You want to add plugin-(type-)specific features, then this must be done on the plugin (type), and not on generic plugin system interfaces.Can you show me which variant plugins depend on which exact cacheable dependency configuration? I can then write some (pseudo) code to show how you can achieve the desired functionality.
Comment #23
berdir@Xano:
That is not correct. The plugin *only* deals with displaying a form that allows a user to configure it. Plugins have no understanding of persistence and where and how things are saved and changed.
Take core blocks as an example. We don't have the problem there because we keep the render cache definitions outside of the plugin but it would have it if plugins would be responsible for defining that. You save block configuration in a block config entity and then display it. When that block is edited (through the plugin, but it doesn't know who is doing that and where it is saved), the block cache tag is invalidated and we need to invalidate all rendered variations of that block.
If you look at #2511570: Remove Drupal\page_manager\Plugin\PageAwareVariantInterface, you can see that it's a bit more complicated there. We have the page manager that has many block configurations, configured through a display plugin and stored in the page. Each block has it's own render cache definition (and the sum of all blocks with their access information is also cached again). All those blocks need to be invalidated if the page is resaved. And the display plugin needs to be able to add cache tags for the page manager page and it needs to get that information from somewhere. This is about providing that.
If you look at the page there, we already did it conditinally if the interface is implemented but I think it makes sense to include it by default so that they're aware of it.
Comment #24
dsnopekUpdated the issue summary and title to emphasize that Panels Everywhere will be impossible in Drupal 8 without this (or similar) change!
Comment #25
wim leersRebased after #2550941: Allow passing contexts to display variants (to enable Panels Everywhere to use static context and relationships), which broke this.
Comment #26
wim leersI think this is ready. My only concerns are about docs.
Does this interface need an explanation what the cacheability metadata it can contain is for?
i.e. that it's about the configuration that this variant depends upon.
The docblock for this class says:
Shouldn't it then also explain that the cacheability metadata describes the plugin configuration?
Comment #27
dsnopekHere's a new patch that should address Wim's review in #26
Comment #28
dsnopekBah! English fail in the last patch. This should be better!
Comment #29
tim.plunkettThanks SO much @Wim Leers for the review.
And thanks @dsnopek.
Comment #30
webchickCommitted and pushed to 8.0.x. YEAH!
Comment #32
dsnopekWhoa! Fastest commit ever. :-) This now retroactively makes @webchick's earlier tweet 100% true!!
Comment #33
dsnopekAnd, of course, thanks to everyone who helped get this one finished! Panels is now fully unblocked!!
Comment #37
tim.plunkettPIFR, so nice of you to get back to us!