Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
In \Drupal\Core\Config\Entity\ConfigEntityBase::preSave() we consult all plugin collections for their up-to-date configuration before saving.
Proposed resolution
We need to do the same thing before serialization.
Remaining tasks
Write tests.
User interface changes
N/A
API changes
N/A, unless you count removing unwanted/unavoidable exceptions as an API change
Data model changes
N/A
Comment | File | Size | Author |
---|---|---|---|
#23 | 2650588-entity-plugin-collection-11.patch | 4.32 KB | Wim Leers |
#2 | 2650588-entity-plugin-collection-2.patch | 1.88 KB | tim.plunkett |
#4 | 2650588-entity-plugin-collection-3.patch | 1.25 KB | tim.plunkett |
#4 | interdiff.txt | 1.93 KB | tim.plunkett |
#5 | 2650588-entity-plugin-collection-5.patch | 1.39 KB | tim.plunkett |
Comments
Comment #2
tim.plunkettComment #3
EclipseGc CreditAttribution: EclipseGc commentedI'm roughly +10000000000 to fixing this. We're having to code around this limitation in page_manager work right now, and it was simple once we figured it out, but then again, most things are.
Eclipse
Comment #4
tim.plunkettActually there's on more step. Unfortunately this cuts down on the reusability part. Ditching the protected method.
Comment #5
tim.plunkettShould really just write those tests...
Comment #6
dawehnerThis could be replaced by
array_filter()
easily.Can't you use an
array_diff
here?Comment #7
tim.plunkettWorking on that, and tests
Comment #8
tim.plunkettNot sure if the array_filter/array_keys are better, but the array_diff is definitely an improvement.
Comment #10
alexpottThis doesn't look tested. I'm missing something, I can't see why it is here.
$this->assertContains() has a better message when it goes wrong.
Comment #11
tim.plunkett#2 is the code that tests #1.
A plugin collection is usually represented in two properties. The array of config used to initialize it, and the property containing the object
The first half of __sleep() handles updating the
$this->pluginConfig
with the correct values.The second half is to unset
$this->pluginCollection
Thanks for the tip about assertContains/assertNotContains, always nice to use the most appropriate assert for a given situation.
Comment #12
dawehnerShould we call serialize() here instead?
Comment #13
tim.plunkettI vote no: I think it's fine to call __ methods in tests, when that is the exact functionality we are testing.
Also, it would be a pain to assert on the serialized result.
Comment #14
tim.plunkettContrib (including two places in page_manager) will need to work around this until it goes in
Comment #15
Wim LeersShouldn't this be extracted into a helper method that
\Drupal\Core\Config\Entity\ConfigEntityBase::preSave()
can then also call?Comment #16
alexpott@Wim Leers I wondered the smae thing put see #4
Comment #17
Wim LeersSo this portion is the same in
::sleep()
and::preSave()
.It's this portion that is different.
Note that in #4, the
unset()
calls were happening in the logic itself. Now it's just being returned, to be unset later. So I think it is possible to have it in a shared helper method. In the::__sleep()
method, you use the return value to unset those entity properties, in the::preSave()
method you just don't do anything with that return value.Comment #18
Wim LeersOops, one newline too many here.
Comment #19
alexpottWell now we're doing this on every save - for no reason...
Comment #20
Wim LeersSolved.
Comment #21
tim.plunkettstring[]|null, or TRUE/FALSE?
Honestly I tried to do it and decided it was cleaner and easier to understand by duplicating the code...
Comment #22
alexpottI agree with @tim.plunkett
Comment #23
Wim LeersAlright. Re-uploading #11 unchanged.
At first I had NFI what this patch was doing, now I do, and I now agree that the duplicated complexity is minimal.
Sorry for the detour!
Comment #24
mondrakeI tested the patch in #23 with the test-only patch in #2393387-32: Add test for editing image effect when configuration form is Ajax enabled, and it seems that it fixes that issue too. Bumping to major as the other issue is triaged major.
Comment #25
alexpottI think this is eligible for 8.0.x since implementing a magic method is not an API change. Also this is fixing a core bug and unblocking contrib.
Committed 9bd6902 and pushed to 8.0.x and 8.1.x. Thanks!
Comment #28
mondrakeI can confirm #2393387: Add test for editing image effect when configuration form is Ajax enabled was fixed by this commit, great!
Would appreciate a review of #2393387-49: Add test for editing image effect when configuration form is Ajax enabled to decide whether to close the issue or still add some test to prevent regressions.
Comment #30
BerdirFor the record, if anyone else ends up looking at this.
This did break one of our modules because we had this logic duplicated. But then the key already didn't exist in it anymore, so array_search() returned FALSE, it casted that to 0 and removed the id from the serialized entity: #2693501: Fix failing ProcessingWebTest
The code here could have the same problem, although I guess we can rely on those being set in $vars. We might still want to make it type safe and check that the return of array_search() is not FALSE.