Problem/Motivation
After opening the 'Edit media' dialog after inserting a media embed in the WYSIWYG, the log is getting a warning, due to an undefined index error.
Set up:
- Clean install of D8.8
- enable Media and Media Library
- On the Full HTML format, enable "Embed Media" filter
- Drag "Insert from Media Library" button onto the Active Toolbar
- For filter settings for the "Embed Media" filter, under "Media types selectable in the Media Library", only allow "Image"
- under "View modes selectable in the 'Edit media' dialog", don't select any
- save Full HTML text format
- go to an article and select Full HTML text format in the WYSWIYG
- Click the "Edit Media" button and save the dialog
- Go to /admin/reports/dblog
- Observe notice
Corresponding log entries include:
Notice: Undefined index: data-view-mode in Drupal\media\Form\EditorMediaDialog->buildForm()
(line 176 of /Users/nathanandersen/dev/d8test/core/modules/media/src/Form/EditorMediaDialog.php)
Note: When the media is inserted, from the Media Library, it doesn't have the data-view-mode assigned:
<drupal-media data-align="center" data-entity-type="media" data-entity-uuid="01209b81-278f-4082-826c-5aa98cb70e6e"></drupal-media>
This issue was split off from #3100067: Unable to adjust anything after inserting Drupal Media, as it was noted in the original bug report, but doesn't seem to be related that issue.
Proposed resolution
Check if the index is undefined before attempting to use it.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#18 | 3100470-18.patch | 3.4 KB | MeenakshiG |
#14 | interdiff-3100470-10-14.txt | 668 bytes | phenaproxima |
#14 | 3100470-14.patch | 3.4 KB | phenaproxima |
#10 | interdiff-3100470-9-10.txt | 890 bytes | phenaproxima |
#10 | 3100470-10.patch | 3.46 KB | phenaproxima |
Comments
Comment #2
oknateHere's a fix for this. I recommend we test manually. I don't think we should write a test that checks if this notice shows up in the logs. We can confirm it manually.
Update: this was the wrong patch, see #4 for the corrected patch.
Comment #3
oknateComment #4
oknateUploaded the wrong patch.
Comment #5
phenaproximaLooks okay to me. We will, however, need a test. But it need not be complex -- it can be a unit or (preferably) kernel test. All it needs to do is directly execute the bad code path, and the notice will cause PHPUnit to fail the test.
Comment #6
oknateHere's test coverage. This will be useful too to test any future changes to that form.
Comment #8
phenaproximaThis looks pretty good to me -- nice work, @oknate! I think we might be able to simplify parts of the test, though.
I think that, since we are using PHP 7 now, we can use the more terse null-coalesce operator here, like so:
This all seems pretty intense -- more like stuff we'd need in a functional test. Can we get away with using mocked objects for at least some of these things?
I don't think this needs to be in a property of the class.
So, I don't know if we need these assertions. We're just testing that the code path doesn't trigger a notice. So honestly, if $build comes back at all without failing the test, we can just use $this->pass() to mark the test as passed.
Comment #9
phenaproximaDid some refactoring of the test; I was able to remove a lot of lines. It's more sparse now, but we can always add more coverage to it later as needed. For now, it's best to just have it test the one thing we want it to test.
Comment #10
phenaproximaReverting an accidental out-of-scope change here.
Comment #12
bnjmnmTwo small changes and this should be ready.
The editor module is not necessary for the test.
The system sequences schema is not necessary for the test.
Comment #13
Wim Leers#12: nice catches!
Clever :) I like it. Much simpler than the usual functional tests.
Comment #14
phenaproximaThank you both! Made the changes requested by @bnjmnm.
Comment #15
Wim LeersComment #16
oknateUnassigning myself. Thanks for the improvements @phenaproxima and @bnjmnm!
Comment #18
MeenakshiG CreditAttribution: MeenakshiG at OpenSense Labs for DrupalFit commentedRe-rolled the patch
Comment #19
Wim LeersThanks, @Meenakshi.g!
Comment #20
alexpottCommitted and pushed 61aa003c83 to 9.0.x and d44b969798 to 8.9.x and 2f209a4eb0 to 8.8.x. Thanks!
Backported to 8.8.x as this is a non disruptive bug fix.