
Problem/Motivation
Discovered as part of #2980304: Seven theme's details/summary focus style is broken/missing in some browsers.
The views-view-table.html.twig template (both from Views module, stable theme, etc) contains this:
{% if (summary is not empty) or (description is not empty) %}
<details>
{% if summary is not empty %}
<summary>{{ summary }}</summary>
{% endif %}
{% if description is not empty %}
{{ description }}
{% endif %}
</details>
{% endif %}
However, the #type => 'details'
render element does more than spit out <details><summary>
. Apparently IE11 doesn't support <details>
properly (https://www.caniuse.com/#feat=details), so there's a JS polyfill that gets injected. Also some Aria-related stuff. So doing this directly in the template means we lose all this goodness, and either this <details>
from the views template will not work and be accessible on some browsers, or we have to duplicate all the stuff the render element does for us.
Proposed resolution
Either:
A) Refactor the Views template to use a render array for the details stuff (via a preprocess?) and then just include the render array in itself.
B) Manually duplicate everything the details render element does inside this Views table template. Nope, this would be gross.
Remaining tasks
Decide what to do.Do it.Write/update tests.- Reviews.
- Write a change record for the template changes
- RTBC.
- Commit.
User interface changes
Views tables with a summary now reuse the default styles for a details
render array element instead of being raw and unstyled. This also ensures that all the appropriate Aria attributes are added to the summary for appropriate accessibility.
Before
After
API changes
None.
Data model changes
None.
Release notes snippet
TBD
Comment | File | Size | Author |
---|---|---|---|
#25 | 3119279.22_25.interdiff.txt | 1.32 KB | dww |
#25 | 3119279-25.89x.patch | 10.81 KB | dww |
#25 | 3119279-25.9xx.patch | 11.88 KB | dww |
Comments
Comment #2
lendudeAdded in #843708: Add option to set caption & remove summary in the html table (Accessibility).
This changes it for all Themes, including Stable, I never remember what we can and cannot change there.
Simplifies the twig, and looks a lot better too :)
Before

After

The test for this passes locally without any changes so all good from that end too it seems.
Edit: So this would be Option A from the IS
Comment #3
dww@Lendude: Sweet, thanks! I didn't expect anyone else to work on this so fast. ;) #2 is clearly a patch for >= 8.9.x, so I requeued for testing on 8.9.x. Re-rolled here for 8.8.x (although I doubt this will get backported that far... maybe).
Also, tagging for accessibility, since I believe the lack of Aria + polyfill stuff makes this an accessibility bug.
Comment #4
dwwHah, right. Classy doesn't want us changing anything in 8.9.x and above. ;) I just pinged @bnjmnm in Slack asking for their input here before we proceed.
Thanks,
-Derek
Comment #5
dwwIn Slack, @bnjmnm said:
So I believe this is the right fix. Passes locally now, at least. ;)
Comment #6
lendude@dww nice, and thanks @bnjmnm!
Since we are marking this as a bug, let's add some test coverage. Also this needs a cache rebuild to pick up the twig template changes.
Let's target 8.9 for now and see if we can backport later?
Comment #8
dww@Lendude: Nice work on the test coverage and post_update! Love it. Almost RTBC.
Agreed on targeting 8.9.x, then worrying about 8.8.x backport later (if it'll be allowed).
I had a tiny nit with the inline comment inside the empty post update. Seemed pointless to duplicate the docblock comment. Since the inline comment is for devs, we might as well explain what the cache rebuild is actually for.
Updating the remaining tasks since we're quite far along now. We're going to want a CR for this, so tagging and adding that to remaining tasks, too. Added the screenshots to the UI changes section.
Also tagging for front-end framework manager review since @lauriii should sign off on this before RTBC.
Yay,
-Derek
Comment #9
lendudeAdded the CR.
While writing the CR I realised we shouldn't backport this to 8.8.x since it will break any existing theme that extends views-view-table.html.twig, it will render the new summary inside the hardcoded summary, causing the theme to show a nested collapsible field.
Would this mean the current patch in #8 is the wrong way to go here? Should we do this in a BC way and not reuse the existing 'summary' variable? Maybe provide a new 'summary_element' (or something) variable and leave the summary variable as it is, and use the new variable in the core templates?
Comment #10
dwwRe: #9: Yeah, agreed. I'm now working on this:
Comment #11
dwwDone. While I was at it, added
summary_element
to the documentation for each template as an available variable.Comment #12
lendudeWe have BC, we have an update, we have test coverage. Seems ready to me.
Comment #13
lendudeUpdated the CR to match the new direction
Comment #14
alexpottThis is not necessary - the twig cache key includes the Drupal version.- turns out my memory is not right - see \Drupal\Core\Template\TwigEnvironment::__construct().Ah but still this is not necessary :)
Here's why. Our container is cached by the drupal version and on container rebuild we're going to run \Drupal\Core\DependencyInjection\Compiler\TwigExtensionPass() and the mtimes of these files will have changed so the container property
twig_extension_hash
will change and twig will be rebuilt.Not having this function means the patch applies to and should be tested against 9.x
Comment #15
neslee canil pintoComment #16
neslee canil pintoComment #18
neslee canil pintoComment #19
dwwNot sure what #15-18 are about. #14 is a pretty straightforward request: don't include any changes to
core/modules/views/views.post_update.php
. /shrugp.s.
Comment #20
lendudeFeedback has been addressed. The trigger for me to add the update was that I had to
drush cr
after applying the patch, but the version number explanation in #14 does cover that nicely, thanks @alexpott!Comment #21
lauriiiTo follow the previous behavior precisely, we should use inline template here. We could potentially use
#plain_text
here too, with the down side that it doesn't take into account if the string has been already escaped.This change should be applied to stable9 too.
Should we open a follow-up for discussing how to deprecate template variables?
Comment #22
dww@lauriii: Thanks for reviewing!
Re: #21:
1. Extremely good point. ;) @Lendude and I discussed in Slack. This isn't just about BC, it's potentially about a security hole by printing the description unescaped. I tested locally/manually and couldn't actually get XSS to happen, but it was changing the escaping behavior such that non-malicious HTML was being rendered as HTML, not escaped. Fixed.
2. Fixed (although we now need separate patches for 8.9.x and 9.x.x).
3. I guess so. Tagging for now.
While I was at it, I noticed an indentation bug in the templates, so I fixed those everywhere (and had to update the md5 hash for core/tests/Drupal/KernelTests/Core/Theme/ConfirmClassyCopiesTest.php again).
Comment #23
dww#3124330: [policy, no patch] Decide on a mechanism to properly deprecate Twig template variables
Comment #24
lendudeitty bitty nit picks
this goes for the 'description' variable too, right?
> 80 characters
lets use $handler->options['description'] so that we don't have to update this when we remove the BC variables
Comment #25
dww@Lendude re: #24: All good points. Fixed.
Comment #26
lendudeLooks great! All feedback has been addressed.
Comment #28
alexpottCommitted and pushed e43c919056 to 9.1.x and 9059fe71a4 to 9.0.x. Committed e3c98f5 and pushed to 8.9.x. Thanks!
Backported to 8.9.x and 9.0.x because accessibility bugs are allowed to be fixed in the rc stage and changing templates prior to a release is better than in a bug fix release.
Comment #32
dwwFantastic, thanks!
Updated the CR to say it was introduced in 8.9.x branch, and published it. I guessed the next version will be 8.9.0-rc1, not beta3. If that's wrong, I guess we can update it again.
Cheers,
-Derek
Comment #33
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedJust seen the change record via RSS. I think the terminology in the change record is confusing, especially the title.
Current CR title: "Views table summary now uses a render array instead of hardcoded summary tags"
The CR title talks about a "table summary", which may mislead people into thinking it's about the old-fashioned
<table summary="">
attribute and/oraria-describedby
. But it's not about either of those things. The words "table" and "summary" are used together in a way that conflates concepts from HTML, WCAG, and Drupal Views. (In fairness, the W3C docs also conflate them, and the settings UI for Views table display aren't clear about how they will be used.)The title of this issue is closer to what the issue was actually about: a
<details>
element. It just happens to be nested inside a table's<caption>
element. I'm going to update the CR.Aside: cramming a
<details>
inside a table<caption>
is a bit elaborate; putting it there in addition to the Twigcaption
variable ("caption for the table" in Views settings) is downright messy. In practice I think you'd use approach one or the other, not both. It certainly isn't clear to from Views UI what will be used as the accessible name of the table. I'll file a new issue about that; I can imagine it has BC implications.Comment #34
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedUpdated the CR. https://www.drupal.org/node/3119928/revisions/view/11856607/11859162
Comment #36
lendudeFollow up for something we missed #3149930: Views table settings exposes "Details" field even when empty