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:

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

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
Issue fork field_formatter-3508059
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
Comment #2
grevil commentedI 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").
Comment #3
grevil commentedOk, 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.
Comment #5
grevil commentedThis should do the trick. Now we are getting the "real" field definition, instead of creating one.
Comment #6
grevil commentedJust did some internal testing and seems to work great! 😁👍
Comment #7
grevil commentedThis issue also fixes #3078962: Field formatter with inline settings does not provide third_party_settings form of target field.
Comment #8
grevil commentedComment #9
shmy commentedI'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:
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:
Comment #10
anybodyComment #11
anybody@grevil: I think my comments will help to resolve the final issues. Let's get this done :)
Comment #12
grevil commentedComment #15
grevil commentedOk, that should do the trick, please re-review!
Comment #16
anybody@grevil GREAT!
All formatters appear now as expected! @thomas.frobieter will be super happy ;)
Comment #18
anybodyComment #19
anybody@grevil could you tag a new release please?