Problem/Motivation
I get the following error in the log when I have two instances of an image effect in a style, whose configuration form specifies an Ajax callback:
PHP Fatal error: Call to a member function validateConfigurationForm() on a non-object in /[...]/core/modules/image/src/Form/ImageEffectFormBase.php on line 111
This happens when editing one of the effect configurations, not when adding them.
Proposed resolution
Let ImageEffectFormBase
implement \Serializable
, and let ::serialize
store only the ImageStyle id and ImageEffect uuid instead of the entire objects.
::unserialize
to reload ImageStyle from storage based on the serialized id, and ImageEffect got based on the serialized uuid from the reloaded ImageStyle object.
Remaining tasks
- Review
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#56 | 2393387-56-test-only.patch | 9.53 KB | mondrake |
#56 | 2393387-56.patch | 5.21 KB | mondrake |
#56 | interdiff_52-56.patch | 1.99 KB | mondrake |
| |||
#52 | 2393387-52.patch | 5.21 KB | mondrake |
Comments
Comment #1
mondrakeTest only patch showing the problem.
Comment #3
mondrakeBack to active.
Comment #4
mondrakeThe problem seems to be with the serialization/unserialization of the imageEffect object while saving the form to KVE for Ajax caching.
The patch attached uses magic __sleep() and __wakeup() methods to ensure that the imageEffect object is recreated upon reading the form from cache.
Comment #9
mondrakeRerolled.
Comment #13
mondrakeRerolled
Comment #15
XanoNice catch! I would store the plugin in
$form_state
instead. That will remove the need for using magic serialization methods.Comment #16
mondrakeRe. #15, in fact, I think the problem here is with the serialization/unserialization of the ImageStyle config entity, so adding elements to $form_state seems not to me the way to go.
I tested the test-only patch in #13 with the latest patch in #1977206: Default serialization of ConfigEntities, and the failure seems to be gone. This may support the point that the problem is generally with ConfigEntity serialization.
Postponing on that issue.
Comment #19
mondrakeRerolled test-only, to check if #2263569: Bypass form caching by default for forms using #ajax. makes any difference here.
Comment #20
mondrake#2263569: Bypass form caching by default for forms using #ajax. fixed this issue too - AJAX forms are no longer cached, so the root cause, being ImageStyle config entity getting serialised and placed in the form cache, is no longer there.
Comment #21
mondrakeComment #22
mondrakeActually no, unfortunately. The issue is still there as soon as the form hits the KVE cache. New test-only patch to demonstrate the issue.
Comment #24
mondrakeReroll of patch in #13 with test-only from #22
Comment #25
mondrakeAn alternative fix, implementing
\Serializable
onImageEffectFormBase
. This is taking cues from #1977206: Default serialization of ConfigEntities, and avoids usage of magic__sleep
and__wakeup
methods.Comment #26
tim.plunkettCan you test this again without the Serializable fixes? Like a tests-only patch? AJAX forms have been changed a lot recently, this may be obsolete.
Comment #28
mondrake@tim.plunkett thanks for feedback. I submitted a retesting request for the test-only in #22, that should still apply. Locally it was failing today on an updated HEAD.
Comment #30
mondrakeTest-only again after #2502785: Remove support for $form_state->setCached() for GET requests and on PHP 5.5
Comment #32
mondrakeReuploading test-only + fix.
Comment #37
xjmConfirmed that this is still a bug per the testing above. We can fix this in a patch release.
Comment #43
mondrakeFull patch in #32 is green. Setting to needs review.
Comment #44
mondrakeUpdated IS with the solution proposed in #25 and later.
Comment #46
gnugetThis looks great, I just found a few details.
The main problem to I found on this patch is the short array syntax and the old syntax is mixed, I think we should use one or the other but just one, (I would prefer the short syntax).
I think here it should be $service_ids = [];
In this patch in another line we used the array's short syntax but here no, I think we should use it here as well to keep the consistency in the patch.
short syntax too.
Array Short syntax as well.
short syntax.
short syntax.
This looks weird, is there a reason why we are doing this?
short syntax.
short syntax.
short syntax.
short syntax.
short syntax.
short syntax.
Comment #47
mondrakeThanks for your review, @gnuget!
It looks like #2650588: Entities with plugin collections should be updated before serialization would solve this issue on the config entity level instead of the approach here, which is on the form level. See comment #2650588-24: Entities with plugin collections should be updated before serialization.
Let's wait for that to go in before continuing, if it is confirmed it will be fixed then I still think it would be worth to have a test only patch to ensure that we do not get regressions in the future.
Comment #49
mondrakeI retested the test-only patch in #32 after commit of #2650588: Entities with plugin collections should be updated before serialization, and it came back green. So the issue is fixed.
I think there are two options for this issue now:
1. We just close it as a duplicate
2. We still review/commit only the test code to prevent possible future regressions. The patch attached here is the test-only in #32, with the changes suggested by @gnuget in #46.
Not changing priority/issue title ATM, as it was triaged major earlier.
Comment #50
alexpottI'm +1 on adding the test.
Comment #51
gnugetI reviewed this again and I just found one really small thing.
Let's remove this extra line here.
Without that extra line this is RTBC to me.
Comment #52
mondrakeHere we go
Comment #53
gnugetComment #54
tim.plunkettTests editing Ajax-enabled image effect forms.
public function
Weird extra spaces here, should only be one
Also can you post a second patch that includes a revert of the core issue that fixed this, so we know for sure the test is testing the right stuff?
Comment #55
mondrakeComment #56
mondrakeThanks @tim.plunkett!
Changes as suggested. The test-only patch reverts commit 9bd6902 from #2650588: Entities with plugin collections should be updated before serialization.
Comment #59
mondrakeSorry wrong .patch extension for the interdiff file.
Comment #60
mondrakeI think I can set this back to RTBC - changes in #56 are minor and it was RTBC before. The test-only patch in #56 show how, reverting the fix in #2650588: Entities with plugin collections should be updated before serialization, we get a failure when posting the form.
Comment #61
alexpottCommitted 822a21f and pushed to 8.0.x and 8.1.x. Thanks!