Problem/Motivation

When modifying an embedded image using 'Image with dimensions' the updated item loses the alt attribute.

Steps to reproduce

  1. Select media item (with pre-existing alt text) to embed within CKEditor field
  2. Update dimensions
  3. Save page and view source
  4. Image has no alt text
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

xrayfish created an issue. See original summary.

ytsurk’s picture

Assigned: Unassigned » ytsurk

Thank you for reporting this issue. I'll have a look at it.

rang501’s picture

Initial try to fix it.

ytsurk’s picture

Assigned: ytsurk » Unassigned

By just looking at the code, this looks fine.
You could move the call to decode within the if clause, so it get's only executed when needed.

ytsurk’s picture

Status: Active » Needs work

I tested now with browser - so, we're allowing the possibility to change the alt-text (+title) for the given media entity.
We do not change the attributes, only overwrite it for the current instance!

This patch helps not adding the attribute to the drupal-media-entity tag, but to the images renderer.

What is really the desired behavior here.
Override or use original? When the fields from the image formatter are empty, we currently show the (inital) placeholder value, which seems fine to me.

Still the title attribute should be treated the same like the alt attribute, so we would need another setting for media_image_title no?

rang501’s picture

Status: Needs work » Needs review

Yeah, my patch probably wasn't correct.

I opened MR for the changes that should find media alt text and also default to media name in case alt is not set.

It doesn't fix the issue with overriding alt text during embedding. There we have an issue where entity_embed module doesn't pass other attributes to formatter and we don't have any information about customized alt text.

raphael apard’s picture

Hi,

Thanks for your work. I'm using this Field Formatter on en entity (not a CKEditor field) and alt attributes is missing too.

Why not get alt from thumbnail ?

https://git.drupalcode.org/project/media_directories/-/blob/2.1.x/module...

raphael apard’s picture

Here my fix

  • ytsurk committed e58d1f9d on 2.1.x
    Issue #3322824 by rang501, Raphael Apard: Alt attribute lost when using...
ytsurk’s picture

This probably got forgotten ..

raphael apard’s picture

I think this is safer to use the getSource method to get the source field instead of using thumbnail.
I my case, alt text is not updated on thumbnail after editing the media.

Here a patch for the 2.0.x version.

raphael apard’s picture

Here a patch for the 2.1.x version (including this fix: https://www.drupal.org/project/media_directories/issues/3366407).

rang501’s picture

Status: Needs review » Closed (outdated)

Marking as outdated. This version is not supported anymore.

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.