Change record status: 
Project: 
Introduced in branch: 
9.5.x
Introduced in version: 
Description: 

Summary

This change exposes a grouping label tag for each view grouping field where the user can specify a wrapping label element by which to group the records within the Views user interface.

Before

Whenever a user chooses to use grouping within a view the title is always wrapped in an <h3> tag.

After

A user can now select an appropriate HTML element based on the context of where they will be using the view.

It looks like:

A select field appears after any grouping field allowing a user to choose a new HTML element

API changes

A new grouping label tag element is 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 views template files:

/core/modules/views/templates/
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

The default value of this key is an <h3> element, which provides backward compatibility for any template that does not use the new grouping label functionality.

Impacts: 
Site builders, administrators, editors
Module developers
Themers