Problem/Motivation
With javascript disabled is not possible to save new media types because (as far as I investigated) the ajax reload of the form fills the source
for the media type but this doesn't happen when no ajax is loaded.
The error on form save is
Error: Call to a member function getName() on null in Drupal\media\MediaSourceBase->prepareFormDisplay() (line 352 of core/modules/media/src/MediaSourceBase.php).
So even the source_field is created and stored but since the source_configuration is still empty it tries to load objects that do not have the configuration updated. With JS enabled this happen on the ajax reload of the form when the user choose a source (File, Image, Video, etc).
I actually bumped into this trying to write tests for
#2988433: Automatically create and configure Media Library view and form displays
since we want to submit the form to trigger the behaviour but using a JS test would be slow and not needed.
Proposed resolution
Fix the case for a non-js submit.
Remaining tasks
- Fix the form
- Write a test
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#12 | interdiff-3018539-6-12.txt | 1.71 KB | phenaproxima |
#12 | 3018539-12.patch | 2.73 KB | phenaproxima |
#6 | 3018539-6.patch | 2.83 KB | phenaproxima |
#6 | 3018539-6-FAIL.patch | 1.61 KB | phenaproxima |
#2 | 3018539-test-only-2.patch | 1.36 KB | rodrigoaguilera |
Comments
Comment #2
rodrigoaguileraIn the case the source field needs to be created the MediaType entity is saved twice because the source field creation depends on the MediaType to be stored and the MediaType needs to be updated with the name of the new field created.
But I can't think of a better way to do this.
Comment #4
rodrigoaguileraCool :)
Back to needs review
Comment #5
phenaproximaThis blocks #2988433: Automatically create and configure Media Library view and form displays, which is a Media Library stable blocker.
Comment #6
phenaproximaThanks, @rodrigoaguilera! And for writing the test first, you rock :)
I found an alternative approach that will not involve saving the media type twice -- hopefully this satisfies all.
Comment #7
phenaproximaComment #9
seanBLooks good. Thanks!
Comment #10
rodrigoaguileraCool, much more elegant :)
Comment #11
alexpottThis looks like a great solution. I think we can improve the comment by making the sentences shorter and more about what occurs rather than what occurs without the fix. Something like:
Tests the media UI without JavaScript.
Just so nobody helpful converts this to a JS test.
Comment #12
phenaproximaThanks! Fixed.
Comment #13
phenaproximaSending this little tyke back to RTBC because all that changed in the last patch is comments.
Comment #14
phenaproximaComment #15
phenaproximaComment #16
alexpottCommitted and pushed 3ba6bc1168 to 8.7.x and 897f0e461e to 8.6.x. Thanks!