Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295751

Allow a custom HTML element to be selected for a grouping field

$
0
0

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

  1. Create a view, either list or table format
  2. Choose Settings on format
  3. 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.

Style options for grouping label in unformatted list settings

Remaining tasks

Contributor tasks needed
TaskNovice task?Contributor instructionsComplete?
Create a merge requestYesMerge request instructionsYes, see gerardc/1383696-c
Get feedback on which tests should be created or modified (or grab tests from related issue) NoInstructionsYes
Write change record for the API changesYesChange record InstructionsYes
Manually test the patch or merge requestNovicePatch test InstructionsNo
Add steps to reproduce the issueNoviceInstructionsYes

User interface changes

Adding a grouping label tag to the style options dialog allows for adjusting the tag per grouping field

Style options for grouping label in unformatted list settings

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.


Viewing all articles
Browse latest Browse all 295751


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>