Problem/Motivation
As you can see from below the H3 tag which is generated from using grouping (@ Format: Unformatted list | Settings:Grouping field) has no divs around it like the regular fields. In my case I would like to wrap some HTML around it but I can't see where. On the fields it's easy, just override the output with what you want but on this generated group title I haven't found how to do this so any help will be much appreciated.
<div class="view-content">
<h2><a href="/blogs/83" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Internet Department</a></h2>
<div class="views-row views-row-1 views-row-odd views-row-first views-row-last">
<div class="views-field views-field-picture">
<div class="field-content">
Steps to reproduce
- Create a view, either list or table format
- Choose Settings on format
- Choose a grouping field to create a grouped display
The output sets the grouping label at a static <h3>
, which can cause heading structure inaccessibility by outputting grouping as incorrect heading levels. This creates possible WCAG violations with no way to remedy as a site builder.
Proposed resolution
Expose a grouping label tag for each grouping field where the user can specify a wrapping label element by which to group the records via the Views UI.
Remaining tasks
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Create a merge request | Yes | Merge request instructions | Yes, see gerardc/1383696-c |
Get feedback on which tests should be created or modified (or grab tests from related issue) | No | Instructions | Yes |
Write change record for the API changes | Yes | Change record Instructions | Yes |
Manually test the patch or merge request | Novice | Patch test Instructions | No |
Add steps to reproduce the issue | Novice | Instructions | Yes |
User interface changes
Adding a grouping label tag to the style options dialog allows for adjusting the tag per grouping field
API changes
A new grouping label tag element is being added to the existing view templates where a static <h3>
was used to wrap a grouping label.
{% if title %} {% if grouping_label_element is empty %} {{ title }} {% else %} <{{ grouping_label_element }}>{{ title }}</{{ grouping_label_element }}> {% endif %} {% endif %}
This code is added to the following files:
- views-view-grouping.html.twig
- views-view-grid-responsive.html.twig
- views-view-grid.html.twig
- views-view-list.html.twig
- views-view-unformatted.html.twig
The {{ grouping_label_element }}
value comes from StylePluginBase.php, which adds a new grouping_label_element array key in the form grouping array and applies if usesGroupingLabelElement = true
. The following PHP style templates have that value set to TRUE:
- DefaultStyle.php
- Grid.php
- GridResponsive.php
- HtmlList.php
By default the value of this key is an <h3>
element, which should prevent breakage of views that don't override the template.
Data model changes
No changes affecting the data model.
Release notes snippet
To be determined.