Problem/Motivation
In fixing #3066802: Ensure that embedded image media items do not display at unreasonable sizes by default, we realized that, once that issue is in, adding a new media type with the "Image" @MediaSource will automatically create a nice, pared-down default display (EntityViewDisplay) for that media type, which just shows the source field.
However, this same nicety doesn't apply to other media types -- if you create, say, a new Remote Video media type, you'll get a bunch of other additional fields (none of which are likely to be as useful to a user as the source field) by default. That kind of sucks.
For example, after creating a new media type (a remote video, in this screenshot, but this would be similar for any media source except Image):

Proposed resolution
All new media types should, by default, show only the source field in their default display. Every @MediaSource plugin should contain the necessary logic for this, and MediaTypeForm already invokes that logic when adding a new media type (calling the source's prepareViewDisplay() method.)
All MediaTypeForm needs to do to fix this issue is remove all components in the default display before calling the source's prepareViewDisplay() method. For example, here's what the default display for a new remote video media type looks like with this patch applied (much cleaner!):

Remaining tasks
Fix this for all media sources in core and write tests, then commit the patch.
User interface changes
TBD, likely none.
API changes
None.
Data model changes
None.
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | interdiff-3081233-16-17.txt | 5.29 KB | phenaproxima |
| #17 | 3081233-17.patch | 10.08 KB | phenaproxima |
| #16 | interdiff-3081233-10-16.txt | 6.49 KB | phenaproxima |
| #16 | 3081233-16.patch | 12.76 KB | phenaproxima |
| #15 | after-embed-ew.png | 309.97 KB | webchick |
Comments
Comment #2
wim leersComment #3
xjmTo evaluate the Media Library roadmap I could use some detail on this issue. Could we add steps to reproduce and maybe a screenshot comparing what happens with Image vs. the other types?
Also, is this only about the UI, or does this also affect the data model itself of the displays created in config? If so, this issue becomes more important to the roadmap as it affects the data models people end up with when using the module (and it's difficult to go back if you set up a data model you don't want). If it would change the actual definitions created, a side-by-side comparison of those would help as well.
Thanks!
Comment #4
phenaproximaThis issue is strictly about the UI, and about the displays that get configured by default. But it doesn't affect data models at all, and almost certainly will not need an update path.
Comment #5
wim leersCorrect. It doesn't affect data models, but it does affect concrete
EntityViewDisplays. But we'd only do this for newly created ones, we wouldn't provide an update path for already-created ones. I think? 🤔 Perhaps that should happen?The view displays we ship with are already doing fine in this regard, for example
<code>core/profiles/standard/config/optional/core.entity_view_display.media.remote_video.default.yml:As you can see, this shows the source field and hides all others.
This issue is about ensuring that this happens by default when creating new
EntityViewDisplays are created for@MediaSources other thanimage.Comment #6
phenaproximaLet's see how many tests this breaks.
Comment #8
phenaproximaThis will fix the tests.
Comment #9
oknateTested.
On Standard install, added Media and Media Library at the same time.
I created new media types for each source, and for each, only the source field was displayed.
I'm going to mark it back as needs work because I think the test coverage should use a count assertion to assert that only one component is enabled. Right now, we're only adding an assertion that the thumbnail isn't enabled. If we don't assert only one component is enabled there could be a regression without the test catching it.
Once that is fixed, I think this is ready.
Comment #10
phenaproximaBehold! I added a generic assertion for this to the base class for Media's JavaScript tests. The method I changed is called by all of the "MediaSource*Test" classes, which cover all of the media source plugins core provides. So this is should be pretty comprehensive. :)
Comment #11
wim leersWe also still need screenshots. Could either one of you do that, @oknate or @phenaproxima? 🙏
Comment #12
phenaproximaAbsolutely.
Comment #13
phenaproximaComment #14
oknateThis looks great now. Marking RTBC, dependent on all the tests on #10 being green. Nice improvement!
Comment #15
webchick#12 weren't quite the screenshots I was after, more the end-user experience... @phenaproxima did a walkthrough, however, and this is a huge improvement, so big +1.
Before, when embedding a new media type:
While a site builder can go in after the fact and clean the display settings up, that's an annoying process, and it's also completely disconnected from the media insertion point.
After, when embedding a new media type:
MUCH better. The only one remaining thing is we should set the Label to "visually hidden." While there might be some use case out there somewhere for exposing Drupal's internal field label to site visitors, core definitely doesn't need that, and so it makes sense for the default to be just the rendered media and that's it.
Also eyeballed the patch; this is great! It's removing code and making the defaults sensible for everyone. Awesome work!
So "needs work" just to tweak the label setting, and then we are good to go!
Comment #16
phenaproximaAnd, done. This makes the label visually hidden by default for anything that extends MediaSourceBase, and for all existing media sources in core. I added test coverage for each individual source, since due to implementation details, each source has to explicitly set the label to visually hidden.
Comment #17
phenaproximaMade some tweaks after a discussion with @oknate and @webchick. They will update the issue with their findings!
Comment #18
oknateI manually retested. I created a new media type with each source that ships with core. For each:
Marking RTBC again, assuming the tests pass.
Comment #19
webchickAwesome stuff.
We had a code review wherein I pointed out that the old tests weren't quite testing "foreach media type, is the label hidden?" but rather if each individual media type's label was being hidden; that's since been fixed.
I was also confused about why we need code like:
But @phenaproxima dug into it with me, and basically, at one point in the display definition process, the default values get merged in and those default values set label to "above." Changing that would mean a change to the field system as a whole (as well as changing like 10+ years of expected behaviour), soooo... definitely out of scope here. ;)
There was an earlier concern raised about changing data models. We don't do that here, but rather defaults, and only for new media types, so there's no impact to existing sites (by design; we don't want to mess with their config, which they've probably already done to work around this problem).
GREAT work here, folks!
Committed and pushed to 8.8.x. Thanks!