Problem/Motivation
When using the "Rendered Entity" formatter for an entity reference field, ll view modes will show up, even the ones for which there is no active display.
Scenario: Check if "Site Builders" can NOT select and use a disabled media view mode, under a referenced field in content/entity types
Given that we do have a media type "Image"
And we do have [size1, size2, size3, size4] media view modes for all media types
And we only enabled [size1, size2, size3] in the "custom display settings" for the "Image" media type
When we create a content type "Image Post"
And add an entity reference "field_image" to the "image" media type
And we go to the "Manage Display" for that content type
And we try to select a media's view mode for the "image" field in a content type's view mode
Then we should see [size1, size2, size3] in the drop-down list.
That is not the case at this time.
Site builders may select the not configured media view mode and it will show some not styled media
Proposed resolution
Only show enabled view modes for the used bundle.
Remaining tasks
Propose a patch for the right way to fix this issue
User interface changes
Only filter and show enabled view modes for a selected bundle.
API changes
N/A
Data model changes
It could be a config or an auto-discovery config
Comments
Comment #2
cilefen commentedComment #3
rajab natshahComment #4
rajab natshahComment #5
marcoscanoThis is actually not media-related, it happens to all other entities as well. The
EntityReferenceEntityFormattersettings currently list all display modes of the target entity, not only the "active" ones.This does make #2831943: Use "rendered media" (not links) as default media field formatter; add modal to configure the used media view mode even worse for Media, though.
Comment #6
marcoscanoComment #11
geek-merlinNot "activated" view modes use the default settings. So IIGIR this is works-as-designed.
Comment #12
rajab natshahThanks, Merlin for following up
Marcos thank you for the explained info
Site Builders may fall into using a none active Display mode
But they are site builders and they should fix that
But in the case of Editors or Content admins
Basic use of adding Media, using the Media Library in the CKEditor
It showing the list of all View modes
It is better to show the list of Display modes on the entity type.
Comment #19
acbramley commentedLooking through how EntityReferenceEntityFormatter works and thinking about possible solutions I'm not sure this is actually achievable without some form of jankiness.
Entity reference fields can allow multiple bundles. If I allow 2 bundles with different "active" view modes, how do we determine what to show in the view mode options?
EntityDisplayRepositorydoes havegetViewModeOptionsByBundle(the formatter currently usesgetViewModeOptionswhich returns all view modes for the entity type), but again we'd have to combine them for each bundle that's configured for the field, etc.Given configuring views is a site builder task, and the Views UI will show a preview, it's simple enough to swap the view mode if it doesn't look correct?
I'm going to close this as works as designed given the length of time since it was last commented on it doesn't seem like a highly desirable change.
Please feel free to reopen if you disagree.
Comment #20
rajab natshahNoted;
Thanks, Adam, for following up.
We're implementing a custom-coded solution for this:
Example: List of default ignored view modes.
This is being handled using multiple _form_alter() hooks in forms.
Maybe the allowed/ignored list could be stored within the same field-form config settings (for fields).