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

  1. Decide what to do.
  2. Do it.
  3. Write/update tests.
  4. Reviews.
  5. Write a change record for the template changes
  6. RTBC.
  7. 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

Screenshot of views table with a summary before the fix

After

Screenshot of views table with a summary after the fix

API changes

None.

Data model changes

None.

Release notes snippet

TBD

Comments

dww created an issue. See original summary.

lendude’s picture

Status: Active » Needs review
StatusFileSize
new23.87 KB
new39.61 KB
new6.55 KB

Added 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

dww’s picture

Issue tags: +Accessibility
StatusFileSize
new3.11 KB

@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.

dww’s picture

Hah, 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

dww’s picture

StatusFileSize
new7.51 KB
new876 bytes

In Slack, @bnjmnm said:

Nice to see tests are doing their job, as annoying as they might be... Since this is basically a bug fix, you can update the hash for this file in the test - this is an acceptable change to Classy (IMO). You’ll also want to copy these changes to any core theme that has this template in a classy/ subdirectory.

So I believe this is the right fix. Passes locally now, at least. ;)

lendude’s picture

Version: 8.8.x-dev » 8.9.x-dev
StatusFileSize
new1.29 KB
new997 bytes
new9.11 KB

@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?

The last submitted patch, 6: 3119279-6-TEST_ONLY.patch, failed testing. View results

dww’s picture

Issue summary: View changes
Issue tags: +Needs change record, +Needs frontend framework manager review
StatusFileSize
new9.02 KB
new473 bytes

@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

lendude’s picture

Issue tags: -Needs change record

Added 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?

dww’s picture

Assigned: Unassigned » dww
Status: Needs review » Needs work

Re: #9: Yeah, agreed. I'm now working on this:

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?

dww’s picture

Assigned: dww » Unassigned
Status: Needs work » Needs review
StatusFileSize
new11.31 KB
new7.38 KB

Done. While I was at it, added summary_element to the documentation for each template as an available variable.

lendude’s picture

Status: Needs review » Reviewed & tested by the community

We have BC, we have an update, we have test coverage. Seems ready to me.

lendude’s picture

Updated the CR to match the new direction

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/views.post_update.php
@@ -436,3 +436,10 @@ function views_post_update_remove_core_key(&$sandbox = NULL) {
+/**
+ * Add proper accessibility to views table summaries.
+ */
+function views_post_update_add_accessibility_for_table_summary(&$sandbox) {
+  // Empty update to cause a cache rebuild to pickup changes to twig templates.
+}

This 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

neslee canil pinto’s picture

Status: Needs work » Needs review
StatusFileSize
new12.26 KB
neslee canil pinto’s picture

StatusFileSize
new10.57 KB

Status: Needs review » Needs work

The last submitted patch, 16: 3119279-26.patch, failed testing. View results

neslee canil pinto’s picture

Status: Needs work » Needs review
StatusFileSize
new9.56 KB
dww’s picture

StatusFileSize
new10.76 KB
new381 bytes

Not 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. /shrug

p.s.

<aside class="git-instructions">
% git pull
% git checkout 8.9.x
% git apply 3119279-11.patch
% git checkout -- core/modules/views/views.post_update.php
% git diff > 3119279-19.patch
% interdiff 3119279-11.patch 3119279-19.patch > 3119279.11_19.interdiff.txt
% git reset --hard HEAD # Wipe the workspace clean of modifications.
% git checkout 9.0.x
% git apply 3119279-19.patch  # See it apply cleanly.
</aside>
lendude’s picture

Status: Needs review » Reviewed & tested by the community

Feedback 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!

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs frontend framework manager review
  1. +++ b/core/modules/views/views.theme.inc
    @@ -660,8 +660,17 @@ function template_preprocess_views_view_table(&$variables) {
       $variables['description'] = $handler->options['description'];
    ...
    +      '#markup' => $variables['description'],
    

    To 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.

  2. +++ b/core/themes/seven/templates/classy/views/views-view-table.html.twig
    index 1f4910a..dddfd00 100644
    --- a/core/themes/stable/templates/views/views-view-table.html.twig
    
    --- a/core/themes/stable/templates/views/views-view-table.html.twig
    +++ b/core/themes/stable/templates/views/views-view-table.html.twig
    

    This change should be applied to stable9 too.

  3. +++ b/core/modules/views/views.theme.inc
    @@ -660,8 +660,17 @@ function template_preprocess_views_view_table(&$variables) {
       $variables['summary'] = $handler->options['summary'];
       $variables['description'] = $handler->options['description'];
    

    Should we open a follow-up for discussing how to deprecate template variables?

dww’s picture

Status: Needs work » Needs review
Issue tags: +Needs followup
StatusFileSize
new11.86 KB
new10.79 KB
new5.93 KB
new6.86 KB

@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).

dww’s picture

lendude’s picture

itty bitty nit picks

  1. +++ b/core/modules/views/views.theme.inc
    @@ -660,8 +660,23 @@ function template_preprocess_views_view_table(&$variables) {
    +  // For backwards compatibility, initialize the 'summary' variable, although
    +  // core templates now all use 'summary_element' instead.
    

    this goes for the 'description' variable too, right?

  2. +++ b/core/modules/views/views.theme.inc
    @@ -660,8 +660,23 @@ function template_preprocess_views_view_table(&$variables) {
    +    // To ensure that the summary description is properly escaped during rendering,
    +    // use an 'inline_template' to let Twig do its magic, instead of 'markup'.
    

    > 80 characters

  3. +++ b/core/modules/views/views.theme.inc
    @@ -660,8 +660,23 @@ function template_preprocess_views_view_table(&$variables) {
    +        'description' => $variables['description'],
    

    lets use $handler->options['description'] so that we don't have to update this when we remove the BC variables

dww’s picture

StatusFileSize
new11.88 KB
new10.81 KB
new1.32 KB

@Lendude re: #24: All good points. Fixed.

lendude’s picture

Status: Needs review » Reviewed & tested by the community

Looks great! All feedback has been addressed.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

alexpott’s picture

Version: 9.1.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 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.

  • alexpott committed e43c919 on 9.1.x
    Issue #3119279 by dww, Lendude, alexpott, lauriii: views-view-table.html...

  • alexpott committed 9059fe7 on 9.0.x
    Issue #3119279 by dww, Lendude, alexpott, lauriii: views-view-table.html...

  • alexpott committed e3c98f5 on 8.9.x
    Issue #3119279 by dww, Lendude, alexpott, lauriii: views-view-table.html...
dww’s picture

Fantastic, 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

andrewmacpherson’s picture

Just 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/or aria-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 Twig caption 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.

andrewmacpherson’s picture

Status: Fixed » Closed (fixed)

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

lendude’s picture