Problem/Motivation

This is a follow-up to #2831943: Users expect rendered media, not links, and configuring the entity reference display and view mode properly is challenging.

After #2831274: Bring Media entity module to core as Media module, users can now create entity reference fields to media entities. The goal is to encourage this approach even when dealing with simple media assets, such as files and images. However, the default formatter for an entity reference field will show the target entity's label, differently from the default formatter of images and files.

In order to make this process as straight-forward as possible, we should pre-configure the formatter when creating a "media field", so that defaults make more sense for that media type.

Proposed resolution

In #2831943: Users expect rendered media, not links, and configuring the entity reference display and view mode properly is challenging, a new entity reference formatter allows to pick a single field from the target entity and render it. The suggestion here is then:
- Detect when a new entity reference field is created for media items, pointing to a single media bundle
- Pre-configure the field's display settings to use the formatter entity_reference_field:
-- show the target's media bundle source field only
-- use defaults that make sense for that bundle / source field type

Remaining tasks

- Decide on the best approach
- Implement it
- Write tests

User interface changes

API changes

Data model changes

Files: 
CommentFileSizeAuthor
#2 2893716-2-do-not-test.patch3.21 KBmarcoscano

Comments

marcoscano created an issue. See original summary.

marcoscano’s picture

Title: [PP-1] Pre-configure formatter "Rendered Field from Referenced Entity" when referencing media entities » Pre-configure formatter "Rendered Field from Referenced Entity" when referencing media entities
Status: Postponed » Needs review
Issue tags: +Needs tests
FileSize
3.21 KB

Actually we don't really need to postpone this issue on #2831943: Users expect rendered media, not links, and configuring the entity reference display and view mode properly is challenging, we can start agreeing on the approach in parallel.

This patch is a first POC of how we could do it. Things we could improve:

1) How to reliably detect if the field has just been created (we can't use hook_ENTITY_TYPE_insert because we need the target bundle, which is set later).

2) If using the media source_field's default_formatter is good enough. It's certainly better than showing the media item's label, but I wonder if we couldn't defer this decision to a new method on MediaSourceInterface, so that source plugins can be more opinionated on which formatter / settings to use.

I haven't created tests yet, once the approach looks good I can go ahead and create them.

NOTE: This patch depends on #2831943-106: Users expect rendered media, not links, and configuring the entity reference display and view mode properly is challenging

phenaproxima’s picture

How to reliably detect if the field has just been created (we can't use hook_ENTITY_TYPE_insert because we need the target bundle, which is set later).

My suggestion: don't even bother trying to detect that. How about we just react when a media reference field is added to an entity view display instead? That will be easy to do -- in fact, Lightning already does it, and we could simply borrow that code. All we want to do is configure the formatter when the field is first added to the view display -- we don't need to care about when the field itself appeared.

Wim Leers’s picture

Status: Needs review » Needs work
Issue tags: +Usability

#3 sounds great :)