From 7e4002382e6eee8fba4023bf2b4e220fa85fdcd5 Mon Sep 17 00:00:00 2001 From: SinghPardeep Date: Tue, 18 Mar 2025 17:10:56 +0000 Subject: [PATCH 1/8] allowing ID randomization but keeping the stable selector --- localgov_base.theme | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/localgov_base.theme b/localgov_base.theme index 2e94ef46..1c949705 100644 --- a/localgov_base.theme +++ b/localgov_base.theme @@ -301,19 +301,23 @@ function localgov_base_views_pre_render(ViewExecutable $view): void { /** * Implements hook_preprocess_container(). */ -function localgov_base_preprocess_container(&$variables): void { - - // Randomize form container IDs for accessibility. + function localgov_base_preprocess_container(&$variables): void { // See https://www.drupal.org/project/drupal/issues/1852090 + // Ensure the container has an ID. if (isset($variables['element']['#id'])) { - $id = $variables['element']['#id']; - if ($id === 'edit-actions') { - $id .= '--' . Crypt::randomBytesBase64(8); + $original_id = $variables['element']['#id']; + + // Only modify 'edit-actions' to prevent affecting other elements. + if ($original_id === 'edit-actions') { + $random_suffix = Crypt::randomBytesBase64(8); + $random_id = $original_id . '--' . $random_suffix; + + // Keep a stable selector but allow ID randomization. + $variables['attributes']['id'] = $random_id; + $variables['attributes']['data-drupal-selector'] = $original_id; + $variables['element']['#attributes']['data-drupal-selector'] = $original_id; + $variables['element']['#id'] = $random_id; } - $variables['attributes']['id'] = $id; - $variables['attributes']['data-drupal-selector'] = $id; - $variables['element']['#attributes']['data-drupal-selector'] = $id; - $variables['element']['#id'] = $id; } } From d5639462da646b17d4b3483c7d5e13c522a90e84 Mon Sep 17 00:00:00 2001 From: SinghPardeep Date: Wed, 19 Mar 2025 11:25:11 +0000 Subject: [PATCH 2/8] resolving ID Randomisation but keeping the stable selector --- localgov_base.theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localgov_base.theme b/localgov_base.theme index 1c949705..e0ddab1e 100644 --- a/localgov_base.theme +++ b/localgov_base.theme @@ -301,7 +301,7 @@ function localgov_base_views_pre_render(ViewExecutable $view): void { /** * Implements hook_preprocess_container(). */ - function localgov_base_preprocess_container(&$variables): void { +function localgov_base_preprocess_container(&$variables): void { // See https://www.drupal.org/project/drupal/issues/1852090 // Ensure the container has an ID. if (isset($variables['element']['#id'])) { From 7432d9eb9f600214341b67b4733e415350c75648 Mon Sep 17 00:00:00 2001 From: SinghPardeep Date: Wed, 26 Mar 2025 14:33:44 +0000 Subject: [PATCH 3/8] all variations of 'edit-actions' get randomized IDs --- localgov_base.theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/localgov_base.theme b/localgov_base.theme index e0ddab1e..ed7f4dca 100644 --- a/localgov_base.theme +++ b/localgov_base.theme @@ -307,8 +307,8 @@ function localgov_base_preprocess_container(&$variables): void { if (isset($variables['element']['#id'])) { $original_id = $variables['element']['#id']; - // Only modify 'edit-actions' to prevent affecting other elements. - if ($original_id === 'edit-actions') { + // Check if the ID starts with 'edit-actions'. + if (strpos($original_id, 'edit-actions') === 0) { $random_suffix = Crypt::randomBytesBase64(8); $random_id = $original_id . '--' . $random_suffix; From 523d04904a21358e2925b6de6c72ee1bbeb73a27 Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Fri, 28 Mar 2025 11:20:36 +0000 Subject: [PATCH 4/8] Move restricted_width_content_types to .theme file (#734) * Move restricted_width_content_types to .theme file * Fix coding standards * Update function name * Fix coding standards --- localgov_base.theme | 30 ++++++++++++++++++++++++++ templates/content/node--full.html.twig | 26 ++++++---------------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/localgov_base.theme b/localgov_base.theme index ed7f4dca..6a8f92b2 100644 --- a/localgov_base.theme +++ b/localgov_base.theme @@ -8,6 +8,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; +use Drupal\Node\NodeInterface; use Drupal\views\ViewExecutable; /** @@ -190,11 +191,40 @@ function localgov_base_preprocess_page(&$variables): void { } +/** + * Get the restricted width content types. + * + * @return array + * An array of restricted width content types. + */ +function _localgov_get_restricted_width_content_types() { + return [ + 'localgov_services_page', + 'localgov_event', + 'localgov_services_status', + 'localgov_step_by_step_overview', + 'localgov_publication_cover_page' + ]; +} + /** * Implements hook_preprocess_HOOK(). */ function localgov_base_preprocess_node(&$variables): void { + $node = $variables['node']; $node_status = $variables['node']->isPublished(); + + if ($node instanceof NodeInterface && $variables['view_mode'] === 'full') { + // Restrict width of the content area to two-thirds of the screen for + // some content types. This is helpful to reduce the line-length for + // better readability. + $variables['restricted_width_content_types'] = []; + if (in_array($node->bundle(), _localgov_get_restricted_width_content_types(), TRUE)) { + $variables['restricted_width_content_types'][] = $node->bundle(); + } + + } + if ($node_status === FALSE) { if (theme_get_setting('localgov_base_add_draft_note_to_unpublished_content') === TRUE) { $variables['label'] = t('[Draft]') . " " . $variables['node']->label(); diff --git a/templates/content/node--full.html.twig b/templates/content/node--full.html.twig index 0915c9bd..0a2f5eb1 100644 --- a/templates/content/node--full.html.twig +++ b/templates/content/node--full.html.twig @@ -71,26 +71,12 @@ */ #} -{# - Restrict width of the content area to two-thirds of the screen for - some content types. This is helpful to reduce the line-length for - better readability. -#} -{% set restricted_width_content_types = [ - 'localgov_services_page', - 'localgov_event', - 'localgov_step_by_step_overview', - 'localgov_services_status', - 'localgov_publication_cover_page' - ] -%} - {% set content_type = node.bundle %} {% if not localgov_base_remove_css %} {{ attach_library('localgov_base/full') }} - {% if content_type == 'localgov_directories_venue' - or content_type == 'localgov_directories_page' + {% if content_type == 'localgov_directories_venue' + or content_type == 'localgov_directories_page' or content_type == 'localgov_directory' %} {{ attach_library('localgov_base/directories') }} {% endif %} @@ -127,7 +113,7 @@ {{ label }} {% endif %} - {{ title_suffix }} + {{ title_suffix }} {% if display_submitted %}
@@ -137,11 +123,11 @@ {{ metadata }}
- {% endif %} + {% endif %} {% if content_type in restricted_width_content_types %}
- {% endif %} + {% endif %} {{ content|without('localgov_subsites_content') }} @@ -151,7 +137,7 @@ {% if node.localgov_subsites_content.value or content.localgov_subsites_content['#type'] == 'layout_paragraphs_builder' %} {{ content.localgov_subsites_content }} {% endif %} - + {% if content_type in restricted_width_content_types %}
From 95be0578791fc2de2e450d0e74c48d8ea0adc1ee Mon Sep 17 00:00:00 2001 From: Chris Gibson Date: Mon, 7 Apr 2025 12:19:16 +0100 Subject: [PATCH 5/8] Copied default safari-pinned-tab.svg into scripts/subtheme-items/assets/images/favicons/ --- .../assets/images/favicons/safari-pinned-tab.svg | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 scripts/subtheme-items/assets/images/favicons/safari-pinned-tab.svg diff --git a/scripts/subtheme-items/assets/images/favicons/safari-pinned-tab.svg b/scripts/subtheme-items/assets/images/favicons/safari-pinned-tab.svg new file mode 100644 index 00000000..ee382952 --- /dev/null +++ b/scripts/subtheme-items/assets/images/favicons/safari-pinned-tab.svg @@ -0,0 +1,13 @@ + + + + +Created by potrace 1.14, written by Peter Selinger 2001-2017 + + + + From 39d486fd1fbb01cee85ea024dce65e017cf79f5a Mon Sep 17 00:00:00 2001 From: Anthony Lindsay Date: Tue, 8 Apr 2025 12:19:30 +0100 Subject: [PATCH 6/8] Extend preprocess block/node to recognise both draft and archived states (#740) * Extend preprocess block/node to recognise both draft and archived states. * Decouple archived label from published state, and add it as a theme setting. * Change == to === for checking theme setting * Add form element and schema entry for archived label theme setting. * Add install config --------- Co-authored-by: Mark Conroy --- config/install/localgov_base.settings.yml | 1 + config/schema/localgov_base.schema.yml | 3 ++ localgov_base.theme | 41 ++++++++++++++++++++--- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/config/install/localgov_base.settings.yml b/config/install/localgov_base.settings.yml index 6d9345c0..ee804895 100644 --- a/config/install/localgov_base.settings.yml +++ b/config/install/localgov_base.settings.yml @@ -2,6 +2,7 @@ localgov_base_remove_css: FALSE localgov_base_remove_js: FALSE localgov_base_add_unpublished_background_colour: TRUE localgov_base_add_draft_note_to_unpublished_content: FALSE +localgov_base_add_archived_note_to_archived_content: FALSE localgov_base_header_behaviour: 'default' localgov_base_localgov_guides_stacked_heading: FALSE localgov_base_localgov_guides_vertical_navigation: TRUE diff --git a/config/schema/localgov_base.schema.yml b/config/schema/localgov_base.schema.yml index 50b4bc6c..b007c508 100644 --- a/config/schema/localgov_base.schema.yml +++ b/config/schema/localgov_base.schema.yml @@ -14,6 +14,9 @@ localgov_base.settings: localgov_base_add_draft_note_to_unpublished_content: type: boolean label: 'Add "[Draft]" to title of unpublished content.' + localgov_base_add_archived_note_to_archived_content: + type: boolean + label: 'Add "[Archived]" to title of archived content.' localgov_base_header_behaviour: type: string label: 'Header behaviour' diff --git a/localgov_base.theme b/localgov_base.theme index 6a8f92b2..11c41c5a 100644 --- a/localgov_base.theme +++ b/localgov_base.theme @@ -43,9 +43,16 @@ function localgov_base_form_system_theme_settings_alter(&$form, FormStateInterfa $form['localgov_base_add_draft_note_to_unpublished_content'] = [ '#type' => 'checkbox', - '#title' => t('Add "Draft" to title of unpublished content.'), + '#title' => t('Add "Draft" to title of draft unpublished content.'), '#default_value' => theme_get_setting('localgov_base_add_draft_note_to_unpublished_content'), - '#description' => t('This adds the word "Draft" to the title of any unpublished content. This is useful if you have removed the pink background from unpublished content.'), + '#description' => t('This adds the word "Draft" to the title of any draft unpublished content. This is useful if you have removed the pink background from unpublished content.'), + ]; + + $form['localgov_base_add_archived_note_to_archived_content'] = [ + '#type' => 'checkbox', + '#title' => t('Add "Archived" to title of archived content.'), + '#default_value' => theme_get_setting('localgov_base_add_archived_note_to_archived_content'), + '#description' => t('This adds the word "Archived" to the title of any content with the "archived" moderation state.'), ]; $form['localgov_base_show_back_to_top_link'] = [ @@ -227,7 +234,19 @@ function localgov_base_preprocess_node(&$variables): void { if ($node_status === FALSE) { if (theme_get_setting('localgov_base_add_draft_note_to_unpublished_content') === TRUE) { - $variables['label'] = t('[Draft]') . " " . $variables['node']->label(); + $state = $variables['node']->get('moderation_state')->getString(); + if ($state == 'draft') { + $variables['label'] = t('[Draft]') . " " . $variables['node']->label(); + } + } + } + // We have a theme setting to prepend 'archived' to the title of + // archived content, but we don't mind whether it is published or not. + // An archived state does not have to always be unpubilshed. + if (theme_get_setting('localgov_base_add_archived_note_to_archived_content') === TRUE) { + $state = $variables['node']->get('moderation_state')->getString(); + if ($state == 'archived') { + $variables['label'] = t('[Archived]') . " " . $variables['node']->label(); } } @@ -254,7 +273,21 @@ function localgov_base_preprocess_block(&$variables): void { if ($node_status === FALSE) { if (theme_get_setting('localgov_base_add_draft_note_to_unpublished_content') === TRUE) { $current_title = $variables['content'][0]['#title']; - $variables['content'][0]['#title'] = t('[Draft]') . " " . $current_title; + $state = $node->get('moderation_state')->getString(); + if ($state == 'draft') { + $variables['content'][0]['#title'] = t('[Draft]') . " " . $current_title; + } + } + } + + // We have a theme setting to prepend 'archived' to the title of + // archived content, but we don't mind whether it is published or not. + // An archived state does not have to always be unpubilshed. + if (theme_get_setting('localgov_base_add_archived_note_to_archived_content') === TRUE) { + $current_title = $variables['content'][0]['#title']; + $state = $node->get('moderation_state')->getString(); + if ($state == 'archived') { + $variables['content'][0]['#title'] = t('[Archived]') . " " . $current_title; } } From bd9d395292da7857ebd2c64a636f85c29554f6d9 Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Tue, 8 Apr 2025 12:37:25 +0100 Subject: [PATCH 7/8] Update node--full to use SDC (#736) * Update node--full to use SDC * Update full view mode SDC * Remove full component, use display-full * Move full.css back to it's original position * Remove client-specific comment (Greenwich) * Remove unused variable --- components/content/content-types/.gitkeep | 0 .../display-full/display-full.component.yml | 0 .../displays/display-full/display-full.twig | 66 ++++++++++++++++ templates/content/node--full.html.twig | 78 ++++--------------- 4 files changed, 79 insertions(+), 65 deletions(-) create mode 100644 components/content/content-types/.gitkeep create mode 100644 components/content/displays/display-full/display-full.component.yml create mode 100644 components/content/displays/display-full/display-full.twig diff --git a/components/content/content-types/.gitkeep b/components/content/content-types/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/components/content/displays/display-full/display-full.component.yml b/components/content/displays/display-full/display-full.component.yml new file mode 100644 index 00000000..e69de29b diff --git a/components/content/displays/display-full/display-full.twig b/components/content/displays/display-full/display-full.twig new file mode 100644 index 00000000..4227c565 --- /dev/null +++ b/components/content/displays/display-full/display-full.twig @@ -0,0 +1,66 @@ +{# + @file Fallback content template to be used for full view mode when no other + more specific template is available. +#} + +{% if not localgov_base_remove_css %} + {{ attach_library('localgov_base/full') }} + {% if content_type == 'localgov_directories_venue' + or content_type == 'localgov_directories_page' + or content_type == 'localgov_directory' %} + {{ attach_library('localgov_base/directories') }} + {% endif %} + + {% if content_type == 'localgov_step_by_step_overview' + or content_type == 'localgov_step_by_step_page' %} + {{ attach_library('localgov_base/step-by-step') }} + {% endif %} +{% endif %} + +{% + set classes = [ + content_type|clean_class, + 'node', + restricted_width_content_type ? 'node--with-restricted-width', + display_full_promoted ? 'node--promoted', + display_full_sticky ? 'node--sticky', + display_full_unpublished ? 'node--unpublished', + view_mode ? 'node--view-mode-' ~ view_mode|clean_class, + ] +%} + + + +
+ {{ title_prefix }} + {{ title_suffix }} + + {% if display_submitted %} +
+ {{ author_picture }} + + {% trans %}Submitted by {{ author_name }} on {{ date }}{% endtrans %} + {{ metadata }} +
+ + {% endif %} + + {% if content_type in restricted_width_content_types %} +
+ {% endif %} + + + {{ display_full_content }} +
+ + + {% if localgov_subsites_content %} + {{ localgov_subsites_content }} + {% endif %} + + + {% if content_type in restricted_width_content_types %} + + {% endif %} + + diff --git a/templates/content/node--full.html.twig b/templates/content/node--full.html.twig index 0a2f5eb1..052e2609 100644 --- a/templates/content/node--full.html.twig +++ b/templates/content/node--full.html.twig @@ -73,74 +73,22 @@ {% set content_type = node.bundle %} -{% if not localgov_base_remove_css %} - {{ attach_library('localgov_base/full') }} - {% if content_type == 'localgov_directories_venue' - or content_type == 'localgov_directories_page' - or content_type == 'localgov_directory' %} - {{ attach_library('localgov_base/directories') }} - {% endif %} - - {% if content_type == 'localgov_event' %} - {{ attach_library('localgov_base/events') }} - {% endif %} - - {% if content_type == 'localgov_step_by_step_overview' - or content_type == 'localgov_step_by_step_page' %} - {{ attach_library('localgov_base/step-by-step') }} - {% endif %} +{% if node.isPromoted() %} + {% set display_full_promoted = TRUE %} {% endif %} -{% - set classes = [ - content_type|clean_class, - 'node', - 'node--type-' ~ node.bundle|clean_class, - content_type in restricted_width_content_types ? 'node--with-restricted-width', - node.isPromoted() ? 'node--promoted', - node.isSticky() ? 'node--sticky', - not node.isPublished() ? 'node--unpublished', - view_mode ? 'node--view-mode-' ~ view_mode|clean_class, - ] -%} - - - -
- {{ title_prefix }} - {% if label and not page %} - - {{ label }} - - {% endif %} - {{ title_suffix }} - - {% if display_submitted %} -
- {{ author_picture }} - - {% trans %}Submitted by {{ author_name }} on {{ date }}{% endtrans %} - {{ metadata }} -
- - {% endif %} - - {% if content_type in restricted_width_content_types %} -
- {% endif %} - - - {{ content|without('localgov_subsites_content') }} -
- +{% if node.isSticky() %} + {% set display_full_sticky = TRUE %} +{% endif %} - {% if node.localgov_subsites_content.value or content.localgov_subsites_content['#type'] == 'layout_paragraphs_builder' %} - {{ content.localgov_subsites_content }} - {% endif %} +{% if not node.isPublished() %} + {% set display_full_unpublished = TRUE %} +{% endif %} +{% set display_full_content = content|without('localgov_subsites_content') %} - {% if content_type in restricted_width_content_types %} - - {% endif %} +{% if node.localgov_subsites_content.value or content.localgov_subsites_content['#type'] == 'layout_paragraphs_builder' %} + {% set localgov_subsites_content = content.localgov_subsites_content %} +{% endif %} - +{% include "localgov_base:display-full" %} From 3b9c543ad4e3be86f58ab7b76927805fde252a6f Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Tue, 8 Apr 2025 12:38:30 +0100 Subject: [PATCH 8/8] Fix coding standard (#746) --- localgov_base.theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/localgov_base.theme b/localgov_base.theme index 11c41c5a..2eb3773e 100644 --- a/localgov_base.theme +++ b/localgov_base.theme @@ -8,7 +8,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; -use Drupal\Node\NodeInterface; +use Drupal\node\NodeInterface; use Drupal\views\ViewExecutable; /**