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
View mode wouldn't appear in "Display" dropdown when editing media embeded into a Full HTML body field.
Steps to reproduce
When I added a view mode for a image media entity I gave it a numerical name (450) and though it appeared as an option to select in /admin/config/content/formats/manage/full_html -> Embed Media it wouldn 't appear in the Display dropdown when I was editing media. After a while I tried again, with a new view mode, this time having a text name (test).. and it worked, and worked again when I came up with other view mode names (Half width, and Quarter width).
Comment | File | Size | Author |
---|---|---|---|
#11 | 3241633-4.patch | 6.04 KB | danflanagan8 |
#4 | 3241633-4.patch | 6.04 KB | danflanagan8 |
#4 | 3241633-4-FAIL.patch | 5.2 KB | danflanagan8 |
#3 | 3241633-3.patch | 856 bytes | danflanagan8 |
Comments
Comment #2
larowlanComment #3
danflanagan8Fun bug! I've dug in a little bit and the source of the problem appears to be the following line in
FilterPluginCollection::initializePlugin()
:Before that, the important part of the media_embed settings looks like this:
But afterwards the numerical array key gets ruined. It then looks something like this:
So later when
array_intersect_key
is called inEditorMediaDialog
to get the available view modes we get unwanted behavior.I've gone ahead and made a one-line change that fixes this bug for me locally. I'm wondering if this will cause anything else to fail. Setting to NR to trigger tests on the patch, but this issue will still need a fail test.
I'm also adding a related issue and tentatively changing the system to which this bug applies.
Comment #4
danflanagan8Ok, back to the fail test. Here's a fail test that updates an existing test such that one of the view modes has a numeric id. The way this will fail is that the View Mode select element won't be found because the form thinks there's only one available View Mode.
I also changed a couple
assertSame
calls toassertEqualsCanonicalizing
so that the order of array elements doesn't matter.Alternatively, I could add a fourth view mode to this test case instead of replacing one of the existing view modes if the community would prefer that.
Comment #6
danflanagan8Ignore that random fail in LayoutBuilderDisableInteractionsTest, a well known random fail.
The relevant test failed as expected:
and was fixed by the other patch.
Comment #7
darvanenFix looks right for the job, code is clean and test coverage is there.
I'm uneasy about altering the existing view mode in the test to include the numerical key rather than creating a third one, but I cannot give any kind of reason as to why which may just mean it comes down to personal preference.
So, since that's the only piece of feedback I would have, this passes community review as far as I'm concerned.
Comment #9
danflanagan8Thanks for the review, @darvanin.
My thinking there was that I was able to avoid adding lines to the test. The downside of doing this was that the message in the fail test was not very clear, which is why I felt the need to give some extra info in #4.
I'm happy to change the test coverage though. Maybe we can see what the core committer thinks?
Regardless, I'm going to change the branch to 9.4.x. Hopefully it doesn't need a re-roll. I think I'll have to manually trigger the tests initially.
Comment #11
danflanagan8The fail test is re-running automatically. I'm re-uploading the good patch here so that's the one that tests run on.
Comment #13
SpokjeBack to RTBC per #7 after #3255836: Test fails due to Composer 2.2 solved the unrelated test failure.
Comment #14
alexpottCommitted and pushed f3b24d25a0a to 10.0.x and 2e7b6ca227f to 9.4.x and adb54155184 to 9.3.x. Thanks!