Problem/Motivation

When using the "Field formatter with inline settings" some field formatters that are available on the field display of the referenced media entity type itself are not available through "Field formatter with inline settings".

Steps to reproduce

1. Add a media video reference field on any node type (Media type "Video")
2. Configure the field display formatter to use "Field formatter with inline settings", choose field name "Video file (field_media_video_file")
3. Click update and save
4. Again: Edit the formatter and check the available formatters:
Reference Field formatter settings
5. Go to the media video display settings (/admin/structure/media/manage/video/display) and check the availble formatters on the "Video file (field_media_video_file)" field. For example, we have a "Video" formatter their, which is missing on the Media reference field with the "Field formatter with inline settings":
Media video file field formatters

Or: Install the https://www.drupal.org/project/plyr module, same problem here: The display formatter "Plyr for video files" is only available on the media entity type itself, but not through the "Field formatter with inline settings"

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

thomas.frobieter created an issue. See original summary.

grevil’s picture

I will have a deeper look. This is caused by how the apllicable formatters are loaded. For each formatter "isApplicable()" is called, but both the Vidstack and Video formatter are extending the core "FileMediaFormatterBase". And their implementation of "isApplicable" fails, because the doesn't apply here, because the "FieldFormatterWithInlineSettings" field definition "file_extensions" setting doesn't include the media mime type (in this case "video").

grevil’s picture

Ok, I found the issue.

Instead of using the actual "real" field defintion of the referenced entity, we create a new one from the given storage definition here.

In the case of the file field, this will lead to "$field_definition->getSetting('file_extensions')" having the default value: "txt", instead of the actual "mp4" value. This in turn, leads to "isApplicable" returning false and the formatter not being displayed.

grevil’s picture

Status: Active » Needs review

This should do the trick. Now we are getting the "real" field definition, instead of creating one.

grevil’s picture

Just did some internal testing and seems to work great! 😁👍

grevil’s picture

Title: Field formatter with inline settings is missing field formatters from the referenced (media) entity type » Field formatter with inline settings is missing field formatters from the referenced (media) entity type or any settings from the original field definition
grevil’s picture

Title: Field formatter with inline settings is missing field formatters from the referenced (media) entity type or any settings from the original field definition » Field formatter with inline settings is missing field formatters from the referenced (media) entity type
shmy’s picture

I've applied MR18 on my local as i need a fix for #3078962: Field formatter with inline settings does not provide third_party_settings form of target field., but i'm getting the folowing warnings on the config form:

Warning: Undefined array key "target_bundles" in Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterWithInlineSettings->settingsForm() (line 208 of modules/contrib/field_formatter/src/Plugin/Field/FieldFormatter/FieldFormatterWithInlineSettings.php).

Warning: foreach() argument must be of type array|object, null given in Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterWithInlineSettings->settingsForm() (line 212 of modules/contrib/field_formatter/src/Plugin/Field/FieldFormatter/FieldFormatterWithInlineSettings.php).

For context purposes, i'm using the formatter on a custom entity type w/o bundles. Looks like that case on not handled by the MR, the $fieldDefinition variable remains NULL if there are no `targetEntityBundleIds` entries.
Core's `Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::defaultConfiguration()` comment on `target_bundles` (defaults to NULL) says:

// For the 'target_bundles' setting, a NULL value is equivalent to "allow
 // entities from any bundle to be referenced" and an empty array value is
 // equivalent to "no entities from any bundle can be referenced".
anybody’s picture

Status: Needs review » Needs work
anybody’s picture

@grevil: I think my comments will help to resolve the final issues. Let's get this done :)

grevil’s picture

Assigned: Unassigned » grevil

grevil’s picture

Assigned: grevil » Unassigned
Status: Needs work » Needs review

Ok, that should do the trick, please re-review!

anybody’s picture

StatusFileSize
new37.99 KB

@grevil GREAT!

All formatters appear now as expected! @thomas.frobieter will be super happy ;)

  • anybody committed 9574665b on 3.x authored by grevil
    Issue #3508059: Field formatter with inline settings is missing field...
anybody’s picture

Status: Needs review » Reviewed & tested by the community
anybody’s picture

Status: Reviewed & tested by the community » Fixed

@grevil could you tag a new release please?

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.