Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
the oEmbedFormatter renders remote video content in an iframe element. This element should contain a title attribute for better accessibility.
https://webaim.org/techniques/frames/#title
Easy fix. Will supply patch shortly.
Comment | File | Size | Author |
---|---|---|---|
#54 | core_button_url_resulting_error.png | 383 bytes | xeM8VfDh |
#54 | core_button_popup.png | 21.3 KB | xeM8VfDh |
#37 | 3021452-21.patch | 5.59 KB | Luke.Leber |
#36 | 3021452-20.patch | 5.6 KB | Luke.Leber |
#34 | 3021452-19.patch | 5.56 KB | Luke.Leber |
Comments
Comment #2
ericmulder1980 CreditAttribution: ericmulder1980 as a volunteer commentedPatch attached.
Comment #3
idebr CreditAttribution: idebr at ezCompany commentedComment #4
Martijn de Witpatch works well, tested with 8.6.x.
Added a test for 8.7 to the patch.
Comment #5
Martijn de WitComment #6
marcoscano+1 for including the title.
The only question I have about the implementation is:
The
$resource->getTitle()
call could return NULL. Is this implementation the best way to accomplish this, or something like:would be more appropriate? (Or in other words, is an empty title attribute any better/worse for a11y than no attribute, or is it the same?)
Comment #7
lauriiiEmpty title attribute will disable inheriting title for the element from its parent (more about title inheritance). I assume that in this case it shouldn't matter but would be great if we could get confirmation from the accessibility maintainers.
Comment #8
seanBWe use the resource title as a default for the title of the media item, but if users want/need to they can override that. Maybe the title of the media item would be better?
#4 @Martijn de Wit, did you forget to upload the new patch with the test?
Comment #9
Martijn de Wit@SeanB No I added a test manually to #2
Comment #10
alexpottI ummed and ahhed on requesting an automated test - imo the fact attributes are added to render elements doesn't need testing - however if we add logic to get different titles depending on what is available then that does need testing. Anyhow it looks like the solution needs a little bit more discussion as to what title to use.
Comment #11
phenaproxima+1 for this patch. But I agree with @lauriii that we need the opinion of the accessibility experts.
Comment #12
phenaproximaDiscussed with @andrewmacpherson on Slack, so removing the accessibility review tag.
Here's what we came up with:
So basically: use the resource title, and do not fall back to the media entity label. If the resource title is null, omit the attribute entirely.
Comment #13
phenaproximaAs per @alexpott's comment in #10, since the title attribute is going to be added conditionally, we are going to need tests.
Comment #14
jibranHere we go.
Comment #17
Luke.LeberDrupalCon Seattle 2019
Rerolled patch for 8.8.x after https://www.drupal.org/project/drupal/issues/2998091 landed.
Comment #18
phenaproximaThanks, @Luke.Leber! Let's see if this passes tests...
Comment #20
Luke.LeberRemove title attribute from 'img' in formatter test.
Image titles do not appear to be in scope for this change.
I believe that we'll still need a test case for ensuring that an empty title is not rendered if the resource title is empty.Comment #21
Luke.LeberComment #22
pawandubey CreditAttribution: pawandubey as a volunteer and at TATA Consultancy Services commentedPatch#20 (3021452-16.patch) tested and working fine. We can move this to RTBC.
Comment #23
phenaproximaLooks right. Thanks!
Comment #24
alexpottThere's comments about how we should avoid
title=""
- what happens if$resource->getTitle()
returns an empty string. Does the resulting html have an empty title attribute? I.e. how comeis crossed out?
Comment #25
Luke.LeberIt looks like if $resource->getTitle returns NULL, then no title attribute is rendered, however if an empty string is returned, then an empty title tag is rendered (at least on 8.8.x - the resource method documentation does not specify a behavior though, so this may be an implementation detail).
From what I can surmise, whether or not a particular OEmbed endpoint does not provide a title key (NULL) or provides an empty one (empty string) is also an implementation detail of each particular provider. The OEmbed spec does not seem to address exactly what should happen in the case of an empty title.
If we want to force all empty strings to omit the title tag, that responsibility will have to be managed either in the formatter, the resource, or the resource fetcher. I do not see any valid reason for a user to explicitly define an empty string for a title tag, so forcing it somewhere within Drupal seems to be a valid conclusion to come to (unless anyone disagrees, of course :) )
It seems reasonable to me to put the check on the formatter so that all legacy media items will be fixed as well when it rolls out. Does anyone else have input?
I had striked the part about having a test for an empty title tag out because line 80 in the formatter test does not specify a title. This was incorrect logic however, because that test doesn't actually work, so I was wrong in striking it out.
Comment #26
Luke.LeberComment #27
Luke.LeberI am probably abusing the core test runner and for this I apologize, but I cannot get the test runner working locally.
For the purpose of code review, I am concerned about the changes to the test case and fixtures. I think there is probably a more elegant way of testing this change that I do not know of.
Comment #28
Luke.LeberComment #29
Luke.LeberComment #30
phenaproximaComment #31
xeM8VfDh CreditAttribution: xeM8VfDh commentedhmm, would love to see this implemented
Comment #32
phenaproximaI would like to request two fairly small, and basically stylistic, changes. Other than that, I really think this looks great.
I think that, rather than hope that the rendering system will always ignore null attributes, we should be more explicit about adding the title if, and only if, it's present. So, I would change this to something like:
This is more of a style thing, but I think more explicit assertions would be useful for future readers of this test. So something like this:
Comment #33
xeM8VfDh CreditAttribution: xeM8VfDh commentedi agree with both 1 and 2 that @phenaproxima posted in #32
Comment #34
Luke.LeberHere's a new patch.
As a side-effect of using the assertContains method, the data providers had to be changed slightly to provide string values. The width, height, max_width, and max_height inputs were failing because assertContains requires either strings or arrays for the first two arguments.
Comment #35
phenaproximaOne minor thing: we can put this line just before
foreach ($attributes as $attribute => $value)
, so we don't need to keep asserting the element's presence for each attribute we're checking.Once this change is made, this is done in my opinion. Feel free to set this issue's status directly to "Reviewed and tested by the community".
Comment #36
Luke.LeberWow, I can't believe that I missed that. Thanks!
I'll wait for the test runner to complete on the latest patch before updating the status.
Comment #37
Luke.LeberComment #38
phenaproximaThanks, @Luke.Leber! All set. RTBC once testbot declares it to be passing.
Comment #39
webchickLooks good. The only addition I'd suggest is a comment above the code to explain the bit about empty titles on iframes being no bueno, since that is useful contextual info. Can always be done on commit. (Basically, a paraphrase of #7.)
I was also confused about:
...this is because we switch from
$assert->elementAttributeContains()
to$this->assertContains()
which needs everything to be strings.Looks good here, and a nice a11y fix! Thanks! Waiting on testbot for the commit.
Comment #41
webchickSaving issue credit.
Comment #43
webchickOk great, committed and pushed to 8.8.x!
For the comment, after the least contentious bikeshedding exercise ever ;) we came up with:
Thanks a lot, everyone!!
Comment #44
phenaproximaThanks, @webchick!
Changing the status to "Patch (to be ported)" because I think that, although this is not a bugfix, it's a non-disruptive accessibility improvement that would benefit 8.7.x.
Comment #45
lauriiiBackporting this seems fine because we're only adding title attribute which is fine since it doesn't affect how the page is rendered visually. Title is coming from content so we don't have to worry about untranslated string translations. This is also added in the render array so that if someone uses alter functions to add their own title, it would be unlikely to be affected by this change. The only risk that I can think of is that someone has set title attribute for the parent element, and this change would lead to overriding that. That seems unlikely, so I think it should be fine to backport this to 8.7.x.
Comment #47
lauriiiComment #48
xeM8VfDh CreditAttribution: xeM8VfDh commentedjust to clarify, will this be released in 8.7.8? Does the title get pulled automatically, or do we have to manually configure it somewhere? THANKS!
Comment #49
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commented@xeM8VfDh
This has been backported to the 8.7.x branch, so it will appear in the next patch release for the 8.7 branch.
There is no configuration involved. Drupal will add a title attribute to the iframe automatically, if the oEmbed resource provides a title.
Comment #50
xeM8VfDh CreditAttribution: xeM8VfDh commentedAwesome, perfect, thanks for the clarification @andrewmacpherson and everyone else who contributed to this.
Comment #52
xeM8VfDh CreditAttribution: xeM8VfDh commentedI don't think this is fully fixed. I opened a separate issue: https://www.drupal.org/project/drupal/issues/3085545
Comment #53
xeM8VfDh CreditAttribution: xeM8VfDh commentedAnyone available to review the new issues?
Comment #54
xeM8VfDh CreditAttribution: xeM8VfDh commentedI don't believe this issue is fixed.
I am running Drupal 8.8.0. I originally had CKEditor Media Embed module enabled. I tested that out by creating a new page and pasting a YouTube url into the page body. The Embed module did it's thing and embedded the video automatically. I saved the page then inspected the source on the youtube video's iframe... no title.
So, I did as @Luke.Leber suggested in #9; I disabled CKEditor Media Embed module. Now my Editor only shows two buttons, the core Drupal Image button, and the "Insert Images using IMCE File Manager" image button.
CORE DRUPAL IMAGE BUTTON
This shows a popup (see attached core_button_popup.png) with a URL field that has a supplemental option to "open file browser". Instead of opening the file browser, I paste my YouTube url into the URL field. I add some alt text, then I save the settings. When I'm returned to the page body in the edit screen, I see a broken image icon (see attached core_button_url_resulting_error.png). I saved the page just for good measure, and nothing displays where the video should be embedded. This doesn't work.
IMCE IMAGE BUTTON
This just opens the IMCE File Browser, the same thing that would happen had I clicked "Open file browser" in the Drupal core image button's popup, explained above. There is no option here to enter a URL.
@Luke.Leber, (or anyone else who has this working) please walk me through how you are embedding your video url, step by step, in precise details please.
Comment #55
xeM8VfDh CreditAttribution: xeM8VfDh commented@pookmish confirmed here that the title attribute isn't working properly.I think I am maybe talking about a different process than he is, which may be the source of my own confusion. He mentioned "video media type", by which I presume he meant this. I am simply wondering about embedding videos into a standard page, or on the test field of some other Content Type. We've historically used the CKEditor Media Embed Plugin to handle this process, and it has worked well for that purpose. But, it doesn't pull in the title attribute.My understanding was that this issue fix somehow allowed us to embed videos into the body field of a page, or some text field of a given Content Type somehow via core functionality, in a way that would include the title attribute for accessibility purposes. Am I misunderstanding this--does the issue in question only address Media Types, and not page/text embeds?See my comment below...
Comment #56
xeM8VfDh CreditAttribution: xeM8VfDh commented@pookmish created a great video demonstrating the exact problem here