Problem/Motivation

#2924391: [media entities] Regardless of @EntityEmbedDisplay plugin, Media entities representing a `image/*` MIME type should be able to have a per-embed `alt` and `title` added per-embed alt and title overrides. Yay! It looks like this:

But what if you want to get rid of your override, and want to revert back to the original?

I'd expect to be able to delete the override I entered and see the original alt text again. But what I see is this:

Proposed resolution

Change it to look like this:

Remaining tasks

  • test coverage
  • review

User interface changes

API changes

Data model changes

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Issue summary: View changes

c/p error

marcoscano’s picture

Category: Task » Bug report
Priority: Normal » Major

I believe #2924391: [media entities] Regardless of @EntityEmbedDisplay plugin, Media entities representing a `image/*` MIME type should be able to have a per-embed `alt` and `title` actually introduced a usability bug. If you create an override, currently there is no way you can restore the original text (i.e. un-override what you did) from the same place you did it.

One way of solving it would be to expose something like a link or button "Revert/Remove override" (or better wording) that removes the overridden value and populates the form element with the original alt text?

oknate’s picture

If alt isn't required, you can simply remove the text in the alt in the dialog and it will go back to displaying the original. But this isn't possible if alt is required. It's also not documented. I think a button next to the alt and a button next to the title [Restore] would work. There is a work around, which is to remove embed and re-embed it.

oknate’s picture

Now that I think about it, I think a button is awkward. The original alt can just be added to the form somewhere hidden, and with javascript, it will be restored when you tab way from the field and the field is empty.

marcoscano’s picture

This is the exact same problem that media in core will (have to) solve in #3023807: Override media fields from the reference field, eventually.

Quoting #3023807-9: Override media fields from the reference field, on the UI aspect of it:

Each overriddeable value will follow what we termed the "machine name pattern", in that the default value will be displayed as a label, with a link or button that says "Edit" (or "Override" -- the jargon is not fleshed out yet) next to it. When you click that button, the value will be instantly displayed in a form field instead, allowing you to change it, and the Edit/Override button will disappear and be replaced by a "Restore default" (or "Revert" or something...again, don't worry about terminology yet) button that, if clicked, will disappear the form field and display the original value as text.

I wonder if we can't experiment with the same approach here, which would be also valuable for validating the approach for media in core?

marcoscano’s picture

Now that I think about it, I think a button is awkward. The original alt can just be added to the form somewhere hidden, and with javascript, it will be restored when you tab way from the field and the field is empty.

There may be legitimate use cases where users might want an empty alt. I'm not sure however how often in real life an image would have an original alt set, but editors would want it to be decorative in some places (the example for having an empty alt)... It's true that we could inform them that something like "" can be used to convey the meaning of "I want to override the original with empty alt here", but maybe an explicit action is clearer?

oknate’s picture

StatusFileSize
new1.86 KB

Here's a patch where upon tabbing away from alt field, if you have left the field blank, it restores the original alt. The same thing with the title field.

oknate’s picture

Oh, and by the way, if want to leave the alt empty, you can put in two double quotes.

oknate’s picture

Issue tags: +Needs tests
oknate’s picture

Issue summary: View changes
oknate’s picture

Issue summary: View changes
Issue tags: -Needs tests
StatusFileSize
new1.63 KB
new3.49 KB

Adding test coverage.

oknate’s picture

Status: Active » Needs review
oknate’s picture

StatusFileSize
new1.81 KB
new3.51 KB

Here's an update that changes it to use the placeholder attribute. It really isn't any different. I thought maybe we should only restore the alt or title if that field is required, but I think it unnecessary, since on the backend it will be doing it anyway. By restoring it in the dialog you make explicit what was previously implicit. Where if the title is not required and they empty it out and it displays the placeholder, but doesn't set the value back to the placeholder, then the UX may be giving the false sense that it won't display the original. It's an easy change to check if it's required and only restore it if it's required.

oknate’s picture

Another approach would be to not set the placeholders to the values until mousedown on the "Embed" button.

oknate’s picture

Here's a version with the approach proposed in #15. Although this begs the question, "Why is alt marked required, if it will be set to the fallback when left blank?" Shouldn't we just not make it required?

Even though the field is required on the original image field, perhaps it shouldn't be in the entity embed dialog, since it will fall back to the original value anyway.

oknate’s picture

Here's a different approach based on this notion in #16:

Why is alt marked required, if it will be set to the fallback when left blank?

This patch removes the required attribute, and simply adds a placeholder. The switching back to the original doesn't need to be in javascript, as it's already happening on the backend.

wim leers’s picture

Thanks, @marcoscano! I agree with your concerns. (That's why I opened this issue in the first place of course.)

  • #16: the problem with that approach is that it won't work for keyboard or touch users.
  • #12 seems viable, except that it's not at all obvious that leaving them empty will inherit the default value — that's why I suggested using the placeholder attribute in the issue summary — that's what you see in the screenshots in the issue summary :)
  • #14 is better than #12 in that it more clearly communicates what's going on, although this automagic-form-field-filling is definitely not a pattern we use anywhere else, so I fear it'll still cause confusion
  • #17 AFAICT implements everything in my suggestions in the issue summary except for using the placeholder attribute ('#placeholder' in form API).
oknate’s picture

Oh dang. I knew there was a '#placeholder' attribute. I was searching the codebase but was searching for 'placeholder' (with single quotes wrapped around the word).

oknate’s picture

  • Adds #placeholder
  • removes unrelated change
    -      // Setting empty alt to double quotes. See ImageFieldFormatter.
    -      if ($settings['title_field_required'] && $title === '') {
    -        $title = static::EMPTY_STRING;
    -      }
    
  • Takes the idea of #17 (not setting default values, but keeping them in the placeholder) even further. We don't need to set the value either.
    -      $alt = isset($attributes['alt']) ? $attributes['alt'] : $entity->{$image_field}->alt;
    -      $title = isset($attributes['title']) ? $attributes['title'] : $entity->{$image_field}->title;
    +      $alt = isset($attributes['alt']) ? $attributes['alt'] : NULL;
    +      $title = isset($attributes['title']) ? $attributes['title'] : NULL;
    

    The placeholder is clear enough.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

This looks great to me. Assigning to @marcoscano for sign-off since he expressed interest in it before :) But as far as I'm concerned, this is ready.

It now behaves exactly like the screenshots I proposed in the issue summary :)

  • Wim Leers committed 3f7d8f3 on 8.x-1.x authored by oknate
    Issue #3060642 by oknate, Wim Leers, marcoscano: Follow-up for #2924391...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new841 bytes
wimleers (he/him) [Today at 2:48 PM]
@marcoscano https://www.drupal.org/project/entity_embed/issues/3060642#comment-13147367 — do you agree with this? @oknate has been addressing your feedback in multiple ways :smile: (edited)

wimleers (he/him)  [1 hour ago]
And I just proposed something slightly different and @oknate already implemented that! As far as I’m concerned, this is good to go. I’d like your +1 before committing :slightly_smiling_face:

wimleers (he/him)  [42 minutes ago]
@oknate I _think_ Marcos might be traveling home from Drupal Dev Days Cluj.

wimleers (he/him)  [42 minutes ago]
Do you also feel very confident that this patch is a net improvement?

wimleers (he/him)  [42 minutes ago]
If so, I’m tempted to just commit it and tag RC2.

oknate  [37 minutes ago]
Have you manually tested it?

wimleers (he/him)  [37 minutes ago]
Yes.

oknate  [37 minutes ago]
Let me test manually one more time, looking at a broader scope.  How much time do you have before you head to the airport?

oknate  [36 minutes ago]
I was just looking at a very narrow range of functionality this morning.

oknate  [34 minutes ago]
I especially want to look at the ‘“”’ override (edited)

marcoscano  [33 minutes ago]
:wave: about to take off now, so cant test it myself atm. But i read the patch and im :thumbsup: with it! Whenever you two think it's ok to go, +1!

marcoscano  [33 minutes ago]
Also, thanks @oknate for jumping in!!

oknate  [12 minutes ago]
I’m noticing one weird thing with the double quotes, but I think it can be handled in a follow up.

If you put alt to “test” and title to ‘“”‘, you get different output, with title missing.  But if you put title to ‘“”’ and alt to “test”, you get alt=“”

<img src=“/sites/simpletest/84354495/files/styles/medium/public/example.jpg?itok=gL4BqF6W” width=“88” height=“100" alt=“” title=“test” class=“image-style-medium”>

<img src=“/sites/simpletest/84354495/files/styles/medium/public/example.jpg?itok=gL4BqF6W” width=“88” height=“100" alt=“test” class=“image-style-medium”>

oknate  [12 minutes ago]
I think that can be handled in a separate issue

oknate  [12 minutes ago]
it really is a separate issue

oknate  [12 minutes ago]
so I think this is good to go

wimleers (he/him)  [9 minutes ago]
YAY!

wimleers (he/him)  [8 minutes ago]
Then I’m committing this and tagging RC2, to avoid people updating to RC1 and re-reporting the same bugs :slightly_smiling_face:

oknate  [7 minutes ago]
great!
marcoscano’s picture

🎉Thanks Nate and Wim! 👏

Status: Fixed » Closed (fixed)

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