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
We added bespoke API for checking whether media entity is for an image (confusingly that's called isMediaUrl on the frontend). However, the frontend will need additional information about the media entity:
Proposed resolution
Refactor isMediaUrl to more generic API that supplies frontend metadata about media entities. The API should provide frontend the following information:
- Whether the media entity contains an image
- The media entity default alt text for the media if it contains an image
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#25 | 3262492-25-d10.patch | 91.53 KB | lauriii |
| |||
#25 | 3262492-25-d94.patch | 91.67 KB | lauriii |
#22 | 3262492-22-d94.patch | 91.65 KB | lauriii |
#22 | 3262492-22-d10.patch | 91.51 KB | lauriii |
#17 | Screenshot 2022-02-14 at 13.58.33.png | 214.55 KB | Wim Leers |
Issue fork drupal-3262492
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
lauriiiComment #3
Wim LeersThis blocks #3246365: [drupalMedia] Show the Image Media's default alt text that is being overridden.
Comment #5
lauriiiThis will also address #3246380: [drupalMedia] Media previews do not update after alt text was modified.
Comment #6
lauriiiComment #7
Wim LeersWonderful progress! :D
Review on the MR.
Comment #8
lauriiiComment #9
Wim LeersHaving dug into #3245720: [drupalMedia] Support choosing a view mode for <drupal-media>, I now know what additional metadata is needed there: the
bundle
(i.e.MediaType
id) of the embedded media. Because different view modes/displays are available for the content author to choose depending on the bundle.(This is a relatively new feature in
\Drupal\media\Form\EditorMediaDialog
for CKEditor 4/other text editors too, see #3097416: When embedding media, don't let authors choose view modes that are not enabled for that media type.)That could easily happen in that issue after this lands. But … it gives me pause to realize that:
TRUE
orFALSE
to indicate whether it is media of theimage
bundle/media type👆 This avoids bundle-specific key-value pairs.
Comment #10
lauriii#9: What would inform the type on your proposal?
I was thinking of something similar and getting the data from
MediaSource
id. However, the media system provides a flexibility to create custom source plugins that could be using the image field. For that reason this MR is following what the current implementation does, and check if the source field is\Drupal\image\Plugin\Field\FieldType\ImageItem
. I'm wondering if we need that flexibility, but this was implemented based on those earlier assumptions.Maybe we need to rename
imageMetadata
since it isn't supposed to be mapped to a specific bundle, or even to a specificMediaSource
plugin.I'm also wondering what would we do in the client if we got response:
Comment #11
Wim LeersForgot about that :/ So let's clarify this by renaming it to `imageSourceMetadata`?
Comment #12
lauriiiComment #13
Wim Leersdrupalmediaediting.js
). But! This is a pre-existing problem. This is significcant progress. And it blocks a stable blocking issue. Therefore this should not hold up this issue. And … we already have an issue for that: #3248432: [drupalImage] Split DrupalImageEditing into multiple plugins.So: 🚢
Comment #14
bnjmnmI switched to this branch then added a media item in the editor. The media element toolbar is not available, just this white arrow. I didn't investigate much beyond that, but when I switch back to HEAD there isn't an issue.
Comment #15
Wim LeersHuh! I definitely did not find that in my manual testing … will try to reproduce. @lauriii, did you ever see this? :O
Comment #16
lauriiiGood catch @bnjmnm! Was able to reproduce. Added test coverage and fixed the bug.
Comment #17
Wim LeersReproduced by only looking at the test coverage that @lauriii added.
I don't see the white arrow that @bnjmnm is referring to, but I do see that the ability to override
alt
for image media was missing in HEAD for freshly inserted media. The fix in https://git.drupalcode.org/project/drupal/-/merge_requests/1787/diffs?co... makes sense too: rather than only handling the fetching of metadata upon upcasting (i.e. for existing media embeds), we now do it also immediately after inserting new media embeds.Comment #18
bnjmnmSetting to NW for visibility on my MR feedback. Most of it is my usual "add too many docs plz" 🙂
Comment #19
lauriiiComment #20
lauriiiMoving back to RTBC to get feedback from @bnjmnm 😇
Comment #21
bnjmnmAll my feedback has been addressed. I'll plan to commit after the commit freeze. In the meantime, patches for 9.3 / 10.0 as needed are welcome!
Comment #22
lauriiiUploading patches for the MR
Comment #24
Wim LeersLooks like a legitimate failure on D10:
Comment #25
lauriiiComment #26
lauriiiMoving back to RTBC because the change from #24 was trivial https://git.drupalcode.org/project/drupal/-/merge_requests/1787/diffs?co....
Comment #27
Wim Leers+1, RTBC++
Comment #31
bnjmnmAdded to 9.4.x / 10.0.x and backported to 9.3.x since CKEditor 5 is experimental.