Problem/Motivation
Can not remove plugins from a config entity during a request because DefaultLazyPluginCollection::$pluginInstances acts as a static cache.
Proposed resolution
Remove unconfigured plugin instances when DefaultLazyPluginCollection::setConfiguration() is called.
Remaining tasks
Review
User interface changes
None
API changes
None
Original issue summary
One example is that image style effects are removed from an exported config file, the removal is not respected when the config file is re-imported.
For example, if I have a set of three image style effects in a file like this:
uuid: 5284900f-2425-4d75-8b49-732c50a2b11e
langcode: en
status: true
dependencies: { }
name: large
label: 'Large (480×480)'
effects:
ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d:
uuid: ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d
id: image_scale
weight: 0
data:
width: 480
height: 480
upscale: false
4e5538ff-1350-4c00-a802-2a12d7556b02:
uuid: 4e5538ff-1350-4c00-a802-2a12d7556b02
id: image_crop
weight: 2
data:
width: 100
height: 100
anchor: right-center
75733cfc-728d-4553-8d07-7bfa15bca63a:
uuid: 75733cfc-728d-4553-8d07-7bfa15bca63a
id: image_desaturate
weight: 3
data: { }
third_party_settings: { }
...Then if I want to remove the Desaturate effect from the file, the import will not remove the effect in Drupal:
uuid: 5284900f-2425-4d75-8b49-732c50a2b11e
langcode: en
status: true
dependencies: { }
name: large
label: 'Large (480×480)'
effects:
ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d:
uuid: ddd73aa7-4bd6-4c85-b600-bdf2b1628d1d
id: image_scale
weight: 0
data:
width: 480
height: 480
upscale: false
4e5538ff-1350-4c00-a802-2a12d7556b02:
uuid: 4e5538ff-1350-4c00-a802-2a12d7556b02
id: image_crop
weight: 2
data:
width: 100
height: 100
anchor: right-center
third_party_settings: { }
So, if I re-export the image style effects, the Desaturate effect will remain.
Comments
Comment #1
webflo commentedThe pluginBag acts like a static cache. This patch enforce rebuilding before entity save.
Comment #2
robertdbailey commentedComment #4
webflo commentedThis issues applied to all config entities with plugin bags. Here is a failing test to show the issue.
Comment #6
webflo commentedComment #7
webflo commentedGo Testbot!
Comment #8
webflo commentedNew title because all Config entities with PluginBags suffer from this issue.
Comment #9
webflo commentedComment #10
dawehnerThis resetting feels really fragile, let's try to avoid it. On top of it, unit tests.
Comment #11
webflo commentedComment #12
jhedstromIt'd be great to have a simple code comment here explaining the unsetting and removal of remaining values.
Comment #15
alexpottRerolled and fixed up DefaultLazyPluginCollectionTest::testConfigurableSetConfiguration() to actually test what it is says it is testing.
Comment #16
alexpottAlso whilst this issue will only appear when a config entity with plugins gets updated and used in the same request it is a pretty big gotcha so I agree with the major priority.
Comment #17
tim.plunkettI think this makes perfect sense.
In response to #12, I clarified some of the comments, and chose to rename the variable to be as specific as possible.
Comment #18
tim.plunkettThough I don't know if the issue title accurately maps to what we're fixing. And not just because Bags are now Collections.
Comment #21
tim.plunkettComment #22
alexpottComment #23
tim.plunkettRTBC again, thanks!
Comment #25
alexpottAn unrelated fail.
Comment #27
alexpottComment #31
alexpottBack to green after all the testbot fun...
Comment #32
alexpottTest only patch as requested by @xjm.
Comment #34
xjmI had to spend a bit of time reading through the API docs to understand why this was necessary (turns out there are actually plugin API docs that cover this now!) but the test-only patch helps clarify that. Thanks @alexpott.
Sounds delicious.
This issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed and pushed to 8.0.x.