Problem/Motivation

This is a follow-up to #2831943: Use "rendered media" (not links) as default media field formatter; add modal to configure the used media view mode.

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: Use "rendered media" (not links) as default media field formatter; add modal to configure the used media view mode, 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

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
StatusFileSize
new3.21 KB

Actually we don't really need to postpone this issue on #2831943: Use "rendered media" (not links) as default media field formatter; add modal to configure the used media view mode, 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: Use "rendered media" (not links) as default media field formatter; add modal to configure the used media view mode

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 :)

Version: 8.4.x-dev » 8.5.x-dev

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

xjm’s picture

#2895382: Hide label, thumbnail, etc. for default display of media file and image references is in now. Can we just use "Rendered entity" instead? I didn't even realize "Rendered field from referenced entity" was a thing.

marcoscano’s picture

Status: Needs work » Closed (outdated)

I didn't even realize "Rendered field from referenced entity" was a thing.

It is not :)

This issue was a follow-up to #2831943: Use "rendered media" (not links) as default media field formatter; add modal to configure the used media view mode in case we implemented this new formatter there (which seemed the way forward around comments 108 - 117 aprox).

Once the "Rendered entity" approach took over in #2831943: Use "rendered media" (not links) as default media field formatter; add modal to configure the used media view mode, this issue has currently no meaning at all, so I'm closing it.

xjm’s picture

Version: 8.5.x-dev » 8.4.x-dev
Status: Closed (outdated) » Closed (duplicate)

Thanks @marcoscano!