-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VACMS-16077: Sets Views Pager Heading Default to H2 (#16425)
* Updates patch to set views pager heading to H2 * updates default header on content and orphaned paragraphs views. * VACMS-16077: updated composer.lock --------- Co-authored-by: Edmund Dunn <[email protected]>
- Loading branch information
1 parent
8cf41d8
commit 11069bd
Showing
5 changed files
with
257 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
245 changes: 245 additions & 0 deletions
245
patches/3333401-configurable-pager-heading-default-h2.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> |