From 9fbc7d4b8f2f8c93c6d2cc939c88110fc8c760d4 Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Thu, 20 Mar 2025 14:12:13 +0000 Subject: [PATCH 1/4] Move restricted_width_content_types to .theme file --- localgov_base.theme | 29 ++++++++++++++++++++++++++ templates/content/node--full.html.twig | 26 ++++++----------------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/localgov_base.theme b/localgov_base.theme index 2e94ef46..9a70f3d4 100644 --- a/localgov_base.theme +++ b/localgov_base.theme @@ -190,11 +190,40 @@ function localgov_base_preprocess_page(&$variables): void { } +/** + * Get the restricted width content types. + * + * @return array + * An array of restricted width content types. + */ +function _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 \Drupal\node\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(), _get_restricted_width_content_types())) { + $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 %} - {% 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 e8a68d9b3ae367b6eb562012bf4c80c1447d69b6 Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Thu, 20 Mar 2025 14:23:15 +0000 Subject: [PATCH 2/4] Fix coding standards --- localgov_base.theme | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/localgov_base.theme b/localgov_base.theme index 9a70f3d4..e7b2c2b8 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; /** @@ -213,7 +214,7 @@ function localgov_base_preprocess_node(&$variables): void { $node = $variables['node']; $node_status = $variables['node']->isPublished(); - if ($node instanceof \Drupal\node\NodeInterface && $variables['view_mode'] === 'full') { + 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. From a1c54fe63d5213db41bf5a9ae9ad32851ae3d8d3 Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Thu, 20 Mar 2025 14:52:23 +0000 Subject: [PATCH 3/4] Update function name --- localgov_base.theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/localgov_base.theme b/localgov_base.theme index e7b2c2b8..4fbf70a7 100644 --- a/localgov_base.theme +++ b/localgov_base.theme @@ -197,7 +197,7 @@ function localgov_base_preprocess_page(&$variables): void { * @return array * An array of restricted width content types. */ -function _get_restricted_width_content_types() { +function _localgov_get_restricted_width_content_types() { return [ 'localgov_services_page', 'localgov_event', @@ -219,7 +219,7 @@ function localgov_base_preprocess_node(&$variables): void { // some content types. This is helpful to reduce the line-length for // better readability. $variables['restricted_width_content_types'] = []; - if (in_array($node->bundle(), _get_restricted_width_content_types())) { + if (in_array($node->bundle(), _localgov_get_restricted_width_content_types())) { $variables['restricted_width_content_types'][] = $node->bundle(); } From db9562c66f6c5cf33f03d3274fe0d9ae02fbbc10 Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Thu, 20 Mar 2025 15:06:48 +0000 Subject: [PATCH 4/4] Fix coding standards --- localgov_base.theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/localgov_base.theme b/localgov_base.theme index 4fbf70a7..03de8342 100644 --- a/localgov_base.theme +++ b/localgov_base.theme @@ -203,7 +203,7 @@ function _localgov_get_restricted_width_content_types() { 'localgov_event', 'localgov_services_status', 'localgov_step_by_step_overview', - 'localgov_publication_cover_page', + 'localgov_publication_cover_page' ]; } @@ -219,7 +219,7 @@ function localgov_base_preprocess_node(&$variables): void { // 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())) { + if (in_array($node->bundle(), _localgov_get_restricted_width_content_types(), TRUE)) { $variables['restricted_width_content_types'][] = $node->bundle(); }