Problem/Motivation

Media entities have the text field "Name" by default. It would be handy to be able to select this as the caption source.

This was mentioned before but I'm not sure what the resolution was. #2900638: Caption Text from Media Name not Working

Steps to reproduce

Proposed resolution

Provide a "Name" option in the caption dropdown. Alternatively, it could provide a list of compatible fields from the media entity as options like it does with the parent entity.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork photoswipe-3305887

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

imclean created an issue. See original summary.

imclean’s picture

Status: Active » Needs review
anybody’s picture

Status: Needs review » Needs work

Hi @imclean,

thank you for your suggestion!
I added some comments. I'm not general against adding this, but the way we're planning to go here is to remove such select values in favor of the token solution.

So could you please check if this already works via tokens or if there's a way to provide the parent entity tokens, if there's a parent entity? That would be more flexible and then no more limited on the name.

imclean’s picture

Status: Needs work » Needs review

I did try tokens first. To get the media field values from the node I need to drill down but tokens for the reference field require a specific delta, which isn't useful.

Media and file tokens don't help here either as the context is the node itself.

"Name" is a standard media field which can't be removed so it seems OK to include a specific option to use it.

anybody’s picture

Status: Needs review » Needs work

I added some more comments.

"Name" is a standard media field which can't be removed so it seems OK to include a specific option to use it.

But ->label() returns the same?

imclean’s picture

But ->label() returns the same?

It seems to. When I first added the option, ->label() returned null. I'm not sure why, maybe a cache issue. It is now returning whatever is entered in the "Name" field of the media entity. I've changed the values a few times to test it.

imclean’s picture

The media entity docs I linked to earlier confirms it. https://api.drupal.org/api/drupal/core%21modules%21media%21src%21Entity%...

The "label" entity key for a media entity is "name".

imclean’s picture

Version: 3.2.1 » 3.x-dev

I think this is the correct dev branch.

imclean’s picture

Status: Needs work » Needs review
anybody’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @imclean,

LGTM!

Grevil made their first commit to this issue’s fork.

grevil’s picture

Status: Reviewed & tested by the community » Fixed

Thx @imclean! Works as expected, for both the field formatter, aswell as the responsive field formatter!

Merging this to dev!

  • Grevil committed 5c888f8 on 3.x authored by imclean
    Issue #3305887 by imclean: Add option to use media Name as caption
    

Status: Fixed » Closed (fixed)

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