Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VACMS-16077: Sets Views Pager Heading Default to H2 #16425

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@
"2942404 - Contentinfo landmark" : "https://www.drupal.org/files/issues/2023-06-30/2942404-messages-should-have-role-status.patch",
"3047110 - Add workflow to taxonomy" : "https://www.drupal.org/files/issues/2023-04-14/3047110-45.patch",
"3106205 - Length of menu_tree.url and menu_tree.route_param_key are too short (255 characters)": "https://www.drupal.org/files/issues/2024-01-02/3106205-length-menu-tree-too-short-48.patch",
"3333401 - Pager h4 cause accessibility flag on many pages": "https://www.drupal.org/files/issues/2023-11-01/3333401-64.patch",
"3333401 - Pager h4 cause accessibility flag on many pages": "patches/3333401-configurable-pager-heading-default-h2.patch",
"3382759 - Add multiple workflow content moderation filter to Views.": "https://www.drupal.org/files/issues/2023-08-24/3382759-8.patch",
"3241295 - CKEditor 5 isn't respecting field widgets row settings": "https://www.drupal.org/files/issues/2023-11-14/3241295-d10.1.6-114.patch",
"3376267 - [upstream] Add style to anchor leads to unusable behavior": "https://www.drupal.org/files/issues/2023-08-09/fix_anchor_scheme_to_not_copy_on_enter-3376167-11.patch"
Expand Down
10 changes: 9 additions & 1 deletion composer.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "1bd88357c60cc37eb2c92720b5436545",
"content-hash": "52a8fc943fb3e90574fb0f0ec2e4a5b0",
"packages": [
{
"name": "asm89/stack-cors",
Expand Down Expand Up @@ -7524,6 +7524,10 @@
"name": "dawehner",
"homepage": "https://www.drupal.org/user/99340"
},
{
"name": "dww",
"homepage": "https://www.drupal.org/user/46549"
},
{
"name": "geek-merlin",
"homepage": "https://www.drupal.org/user/229048"
Expand Down Expand Up @@ -9331,6 +9335,10 @@
"name": "amitaibu",
"homepage": "https://www.drupal.org/user/57511"
},
{
"name": "bluegeek9",
"homepage": "https://www.drupal.org/user/1286304"
},
{
"name": "jhedstrom",
"homepage": "https://www.drupal.org/user/208732"
Expand Down
2 changes: 1 addition & 1 deletion config/sync/views.view.content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ display:
offset: false
offset_label: Offset
quantity: 9
pagination_heading_level: h4
pagination_heading_level: ''
exposed_form:
type: basic
options:
Expand Down
2 changes: 1 addition & 1 deletion config/sync/views.view.orphaned_paragraphs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ display:
offset: false
offset_label: Offset
quantity: 9
pagination_heading_level: h4
pagination_heading_level: ''
exposed_form:
type: basic
options:
Expand Down
245 changes: 245 additions & 0 deletions patches/3333401-configurable-pager-heading-default-h2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
diff --git a/core/modules/views/src/Plugin/views/pager/SqlBase.php b/core/modules/views/src/Plugin/views/pager/SqlBase.php
index 11cbaf44901be7c0e09ba1206fa5def80a92956a..135d32644c038a9bff7f494b89e9685aed9c592f 100644
--- a/core/modules/views/src/Plugin/views/pager/SqlBase.php
+++ b/core/modules/views/src/Plugin/views/pager/SqlBase.php
@@ -68,6 +68,7 @@ abstract class SqlBase extends PagerPluginBase implements CacheableDependencyInt
$options['offset'] = ['default' => 0];
$options['id'] = ['default' => 0];
$options['total_pages'] = ['default' => ''];
+ $options['pagination_heading_level'] = ['default' => 'h2'];
$options['expose'] = [
'contains' => [
'items_per_page' => ['default' => FALSE],
diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
index 11cbaf44901be7c0e09ba1206fa5def80a92956a..135d32644c038a9bff7f494b89e9685aed9c592f 100644
--- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
+++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php
@@ -780,6 +780,38 @@ public function isDefaulted($option) {
return !$this->isDefaultDisplay() && !empty($this->default_display) && !empty($this->options['defaults'][$option]);
}

+ /**
+ * Extracts heading elements from views configuration (@field_rewrite_elements).
+ */
+ public function getHeadings() {
+ static $headings = NULL;
+ if (!isset($headings)) {
+ $elements = \Drupal::config('views.settings')->get('field_rewrite_elements');
+ foreach ($elements as $key => $element) {
+ if (strlen($key) == 2 && $element[0] == 'H') {
+ $headings[$key] = $element;
+ }
+ }
+ }
+ return $headings;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getElements() {
+ static $elements = NULL;
+ if (!isset($elements)) {
+ // @todo Add possible html5 elements.
+ $elements = [
+ '' => $this->t('- Use default -'),
+ ];
+ $elements += $this->getHeadings();
+ }
+
+ return $elements;
+ }
+
/**
* {@inheritdoc}
*/
@@ -1871,6 +1887,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['pager_options'] = [
'#tree' => TRUE,
];
+ $form['pager_options']['pagination_heading_level'] = [
+ '#title' => $this->t('Heading Level'),
+ '#options' => $this->getElements(),
+ '#type' => 'select',
+ '#default_value' => $plugin->getHeadingLevel(),
+ '#description' => $this->t('Choose a heading level equal to or one lower than the preceding header.'),
+ '#fieldset' => 'style_settings',
+ ];
$plugin->buildOptionsForm($form['pager_options'], $form_state);
}
break;
diff --git a/core/modules/views/src/Plugin/views/pager/PagerPluginBase.php b/core/modules/views/src/Plugin/views/pager/PagerPluginBase.php
index d02f67034417598829cf41ee2f144092df29bac4..1675f09ab978cb23f296d98c0ba02521fe5c6157 100644
--- a/core/modules/views/src/Plugin/views/pager/PagerPluginBase.php
+++ b/core/modules/views/src/Plugin/views/pager/PagerPluginBase.php
@@ -72,6 +72,20 @@ public function setOffset($offset) {
$this->options['offset'] = $offset;
}

+ /**
+ * Get the pager heading tag.
+ */
+ public function getHeadingLevel() {
+ return $this->options['pagination_heading_level'] ?? 'h2';
+ }
+
+ /**
+ * Set the pager heading.
+ */
+ public function setHeadingLevel($headingLevel) {
+ $this->options['pagination_heading_level'] = $headingLevel;
+ }
+
/**
* Get the current page.
*
diff --git a/core/modules/views/src/Plugin/views/pager/Full.php b/core/modules/views/src/Plugin/views/pager/Full.php
index d02f67034417598829cf41ee2f144092df29bac4..1675f09ab978cb23f296d98c0ba02521fe5c6157 100644
--- a/core/modules/views/src/Plugin/views/pager/Full.php
+++ b/core/modules/views/src/Plugin/views/pager/Full.php
@@ -86,10 +86,14 @@ public function render($input) {
3 => $this->options['tags']['next'],
4 => $this->options['tags']['last'],
];
+ $heading_options = [
+ 'pagination_heading_level' => parent::getHeadingLevel(),
+ ];
return [
'#theme' => $this->themeFunctions(),
'#tags' => $tags,
'#element' => $this->options['id'],
+ '#options' => $heading_options,
'#parameters' => $input,
'#quantity' => $this->options['quantity'],
'#route_name' => !empty($this->view->live_preview) ? '<current>' : '<none>',
diff --git a/core/modules/views/src/Plugin/views/pager/Mini.php b/core/modules/views/src/Plugin/views/pager/Mini.php
index d02f67034417598829cf41ee2f144092df29bac4..1675f09ab978cb23f296d98c0ba02521fe5c6157 100644
--- a/core/modules/views/src/Plugin/views/pager/Mini.php
+++ b/core/modules/views/src/Plugin/views/pager/Mini.php
@@ -93,10 +93,14 @@ public function render($input) {
1 => $this->options['tags']['previous'],
3 => $this->options['tags']['next'],
];
+ $heading_options = [
+ 'pagination_heading_level' => parent::getHeadingLevel(),
+ ];
return [
'#theme' => $this->themeFunctions(),
'#tags' => $tags,
'#element' => $this->options['id'],
+ '#options' => $heading_options,
'#parameters' => $input,
'#route_name' => !empty($this->view->live_preview) ? '<current>' : '<none>',
];
diff --git a/core/themes/claro/templates/pager.html.twig b/core/themes/claro/templates/pager.html.twig
index d02f67034417598829cf41ee2f144092df29bac4..1675f09ab978cb23f296d98c0ba02521fe5c6157 100644
--- a/core/themes/claro/templates/pager.html.twig
+++ b/core/themes/claro/templates/pager.html.twig
@@ -36,7 +36,8 @@
#}
{% if items %}
<nav class="pager" role="navigation" aria-labelledby="{{ heading_id }}">
- <h4 id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</h4>
+ {% set hx = pager['#options']['pagination_heading_level'] ?: 'h2' %}
+ <{{ hx }} id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</{{ hx }}>
<ul class="pager__items js-pager__items">
{# Print first item if we are not on the first page. #}
{% if items.first %}
diff --git a/core/themes/claro/templates/views/views-mini-pager.html.twig b/core/themes/claro/templates/views/views-mini-pager.html.twig
index d02f67034417598829cf41ee2f144092df29bac4..1675f09ab978cb23f296d98c0ba02521fe5c6157 100644
--- a/core/themes/claro/templates/views/views-mini-pager.html.twig
+++ b/core/themes/claro/templates/views/views-mini-pager.html.twig
@@ -19,7 +19,8 @@
%}
{% if items.previous or items.next %}
<nav{{ attributes.addClass('pager').setAttribute('role', 'navigation').setAttribute('aria-labelledby', heading_id) }}>
- <h4{{ title_attributes.addClass('visually-hidden').setAttribute('id', heading_id) }}>{{ 'Pagination'|t }}</h4>
+ {% set hx = options['pagination_heading_level'] ?: 'h2' %}
+ <{{ hx }}{{ title_attributes.addClass('visually-hidden').setAttribute('id', heading_id) }}>{{ 'Pagination'|t }}</{{ hx }}>
<ul{{ content_attributes.addClass('pager__items', 'js-pager__items') }}>
{% if items.previous %}
{% apply spaceless %}
diff --git a/core/themes/olivero/templates/navigation/pager.html.twig b/core/themes/olivero/templates/navigation/pager.html.twig
index d02f67034417598829cf41ee2f144092df29bac4..1675f09ab978cb23f296d98c0ba02521fe5c6157 100644
--- a/core/themes/olivero/templates/navigation/pager.html.twig
+++ b/core/themes/olivero/templates/navigation/pager.html.twig
@@ -32,7 +32,8 @@
#}
{% if items %}
<nav class="pager layout--content-medium" role="navigation" aria-labelledby="{{ heading_id }}">
- <h4 id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</h4>
+ {% set hx = pager['#options']['pagination_heading_level'] ?: 'h2' %}
+ <{{ hx }} id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</{{ hx }}>
<ul class="pager__items js-pager__items">
{# Print first item if we are not on the first page. #}
{% if items.first %}
diff --git a/core/themes/olivero/templates/views/views-mini-pager.html.twig b/core/themes/olivero/templates/views/views-mini-pager.html.twig
index d02f67034417598829cf41ee2f144092df29bac4..1675f09ab978cb23f296d98c0ba02521fe5c6157 100644
--- a/core/themes/olivero/templates/views/views-mini-pager.html.twig
+++ b/core/themes/olivero/templates/views/views-mini-pager.html.twig
@@ -12,7 +12,8 @@
#}
{% if items.previous or items.next %}
<nav class="pager" role="navigation" aria-labelledby="{{ heading_id }}">
- <h4 id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</h4>
+ {% set hx = options['pagination_heading_level'] ?: 'h2' %}
+ <{{ hx }}{{ title_attributes.addClass('visually-hidden').setAttribute('id', heading_id) }}>{{ 'Pagination'|t }}</{{ hx }}>
<ul class="pager__items js-pager__items">
{# Print previous item if we are not on the first page. #}
{% if items.previous %}
diff --git a/core/themes/stable9/templates/navigation/pager.html.twig b/core/themes/stable9/templates/navigation/pager.html.twig
index 6f863faaf9..9616577558 100644
--- a/core/themes/stable9/templates/navigation/pager.html.twig
+++ b/core/themes/stable9/templates/navigation/pager.html.twig
@@ -32,7 +32,8 @@
#}
{% if items %}
<nav class="pager" role="navigation" aria-labelledby="{{ heading_id }}">
- <h4 id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</h4>
+ {% set hx = pager['#options']['pagination_heading_level'] ?: 'h2' %}
+ <{{ hx }} id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</{{ hx }}>
<ul class="pager__items js-pager__items">
{# Print first item if we are not on the first page. #}
{% if items.first %}
diff --git a/core/themes/stable9/templates/views/views-mini-pager.html.twig b/core/themes/stable9/templates/views/views-mini-pager.html.twig
index 24f8f7aa99..12eb5b2353 100644
--- a/core/themes/stable9/templates/views/views-mini-pager.html.twig
+++ b/core/themes/stable9/templates/views/views-mini-pager.html.twig
@@ -12,7 +12,8 @@
#}
{% if items.previous or items.next %}
<nav role="navigation" aria-labelledby="{{ heading_id }}">
- <h4 id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</h4>
+ {% set hx = options['pagination_heading_level'] ?: 'h2' %}
+ <{{ hx }}{{ title_attributes.addClass('visually-hidden').setAttribute('id', heading_id) }}>{{ 'Pagination'|t }}</{{ hx }}>
<ul class="js-pager__items">
{% if items.previous %}
<li>
diff --git a/core/themes/starterkit_theme/templates/navigation/pager.html.twig b/core/themes/starterkit_theme/templates/navigation/pager.html.twig
index 6f863faaf9..9616577558 100644
--- a/core/themes/starterkit_theme/templates/navigation/pager.html.twig
+++ b/core/themes/starterkit_theme/templates/navigation/pager.html.twig
@@ -32,7 +32,8 @@
#}
{% if items %}
<nav class="pager" role="navigation" aria-labelledby="{{ heading_id }}">
- <h4 id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</h4>
+ {% set hx = pager['#options']['pagination_heading_level'] ?: 'h2' %}
+ <{{ hx }} id="{{ heading_id }}" class="visually-hidden">{{ 'Pagination'|t }}</{{ hx }}>
<ul class="pager__items js-pager__items">
{# Print first item if we are not on the first page. #}
{% if items.first %}
diff --git a/core/themes/starterkit_theme/templates/views/views-mini-pager.html.twig b/core/themes/starterkit_theme/templates/views/views-mini-pager.html.twig
index 4b46f2bb1f..585fe7242a 100644
--- a/core/themes/starterkit_theme/templates/views/views-mini-pager.html.twig
+++ b/core/themes/starterkit_theme/templates/views/views-mini-pager.html.twig
@@ -12,7 +12,8 @@
#}
{% if items.previous or items.next %}
<nav class="pager" role="navigation" aria-labelledby="{{ heading_id }}">
- <h4 id="{{ heading_id }}" class="pager__heading visually-hidden">{{ 'Pagination'|t }}</h4>
+ {% set hx = options['pagination_heading_level'] ?: 'h2' %}
+ <{{ hx }}{{ title_attributes.addClass('visually-hidden').setAttribute('id', heading_id) }}>{{ 'Pagination'|t }}</{{ hx }}>
<ul class="pager__items js-pager__items">
{% if items.previous %}
<li class="pager__item pager__item--previous">
Loading