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

RajabNatshah created an issue. See original summary.

cilefen’s picture

Title: Site Builders can select and use a not enabled media view mode, under a referenced field in content/entity types » Site Builders can select and use a disabled media view mode, under a referenced field in content/entity types
rajab natshah’s picture

Issue summary: View changes
rajab natshah’s picture

Issue summary: View changes
marcoscano’s picture

Title: Site Builders can select and use a disabled media view mode, under a referenced field in content/entity types » Site Builders can select and use a non-active display modes in EntityReferenceEntityFormatter settings
Version: 8.5.x-dev » 8.6.x-dev
Component: media system » entity system
Issue summary: View changes
Issue tags: -media, -view modes, -manage display +Media Initiative
Related issues: +#2831943: Use "rendered media" (not links) as default media field formatter; add modal to configure the used media view mode

This is actually not media-related, it happens to all other entities as well. The EntityReferenceEntityFormatter settings 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.

marcoscano’s picture

Title: Site Builders can select and use a non-active display modes in EntityReferenceEntityFormatter settings » Site Builders can select non-active display modes in EntityReferenceEntityFormatter settings

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

geek-merlin’s picture

Not "activated" view modes use the default settings. So IIGIR this is works-as-designed.

rajab natshah’s picture

Thanks, 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.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

acbramley’s picture

Status: Active » Closed (works as designed)
Issue tags: +Bug Smash Initiative

Looking 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? EntityDisplayRepository does have getViewModeOptionsByBundle (the formatter currently uses getViewModeOptions which 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.

rajab natshah’s picture

Noted;
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).