From 322e4e2de78189d4f6cc51dd1c6314ad74adc238 Mon Sep 17 00:00:00 2001 From: Feb Dao Date: Fri, 7 Mar 2025 15:30:50 +1100 Subject: [PATCH] [CIVIC-2042] Fixed CR. --- ...ock.block.civictheme_mobile_navigation.yml | 2 +- ...ck.block.civictheme_primary_navigation.yml | 2 +- .../block.block.civictheme_search.yml | 2 +- .../civictheme/includes/mobile_navigation.inc | 27 ++++++++++++++++--- .../contrib/civictheme/includes/search.inc | 7 +---- .../contrib/civictheme/includes/utilities.inc | 19 ------------- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/web/themes/contrib/civictheme/config/optional/block.block.civictheme_mobile_navigation.yml b/web/themes/contrib/civictheme/config/optional/block.block.civictheme_mobile_navigation.yml index b6e6d816c7..5185435742 100644 --- a/web/themes/contrib/civictheme/config/optional/block.block.civictheme_mobile_navigation.yml +++ b/web/themes/contrib/civictheme/config/optional/block.block.civictheme_mobile_navigation.yml @@ -6,7 +6,7 @@ dependencies: id: civictheme_mobile_navigation theme: civictheme region: header_middle_3 -weight: 0 +weight: -1 provider: null plugin: 'block_content:b7f36176-620f-4178-aadd-9b448c610986' settings: diff --git a/web/themes/contrib/civictheme/config/optional/block.block.civictheme_primary_navigation.yml b/web/themes/contrib/civictheme/config/optional/block.block.civictheme_primary_navigation.yml index 09119cad3f..44af7c721a 100644 --- a/web/themes/contrib/civictheme/config/optional/block.block.civictheme_primary_navigation.yml +++ b/web/themes/contrib/civictheme/config/optional/block.block.civictheme_primary_navigation.yml @@ -10,7 +10,7 @@ dependencies: id: civictheme_primary_navigation theme: civictheme region: header_middle_3 -weight: 0 +weight: -3 provider: null plugin: 'menu_block:civictheme-primary-navigation' settings: diff --git a/web/themes/contrib/civictheme/config/optional/block.block.civictheme_search.yml b/web/themes/contrib/civictheme/config/optional/block.block.civictheme_search.yml index d934fc2661..c221e81182 100644 --- a/web/themes/contrib/civictheme/config/optional/block.block.civictheme_search.yml +++ b/web/themes/contrib/civictheme/config/optional/block.block.civictheme_search.yml @@ -6,7 +6,7 @@ dependencies: id: civictheme_search theme: civictheme region: header_middle_3 -weight: 0 +weight: -2 provider: null plugin: 'block_content:286ff750-a9a9-423a-8a4e-515f79fc0a8f' settings: diff --git a/web/themes/contrib/civictheme/includes/mobile_navigation.inc b/web/themes/contrib/civictheme/includes/mobile_navigation.inc index 14672900fd..e2a7c7a429 100644 --- a/web/themes/contrib/civictheme/includes/mobile_navigation.inc +++ b/web/themes/contrib/civictheme/includes/mobile_navigation.inc @@ -39,8 +39,29 @@ function _civictheme_preprocess_block__civictheme_mobile_navigation(array &$vari 'bottom_menu' => 'field_c_b_bottom', ]; - // Retrieve the search link. - $search_link = _civictheme_search_link(); + // Load all blocks of type 'civictheme_search' + $block_storage = \Drupal::entityTypeManager()->getStorage('block_content'); + $blocks = $block_storage->loadByProperties(['type' => 'civictheme_search']); + + // Initialize an empty array to store the search link. + $search_link = []; + + // Iterate through the blocks and do something with them. + /** @var \Drupal\block_content\Entity\BlockContent $block */ + foreach ($blocks as $block) { + // Get the field values directly from the block content entity. + $link_in_mobile_menu = $block->get('field_c_b_link_in_mobile_menu')->value ?? FALSE; + + if ($link_in_mobile_menu) { + $link = civictheme_get_field_value($block, 'field_c_b_link', TRUE); + if ($link !== NULL) { + $search_link = [ + 'url' => $link->getUrl()->toString(), + 'text' => $link->get('title')->getString(), + ]; + } + } + } // Get primary and secondary menu links by building menu tree based on // menu block settings. @@ -84,7 +105,7 @@ function _civictheme_preprocess_block__civictheme_mobile_navigation(array &$vari $variables[$menu_key] = $build['#items'] ?? []; // Add search link to end of top menu. - if ($menu_key === 'top_menu' && $search_link) { + if ($menu_key === 'top_menu' && !empty($search_link)) { $variables[$menu_key][] = [ 'url' => $search_link['url'], 'title' => $search_link['text'], diff --git a/web/themes/contrib/civictheme/includes/search.inc b/web/themes/contrib/civictheme/includes/search.inc index 8d73d7dd4d..3a64f1b18c 100644 --- a/web/themes/contrib/civictheme/includes/search.inc +++ b/web/themes/contrib/civictheme/includes/search.inc @@ -28,14 +28,9 @@ function civictheme_preprocess_block__civictheme_search(array &$variables): void if ($link !== NULL) { $variables['url'] = $link->getUrl()->toString(); $variables['text'] = $link->get('title')->getString(); - if ($entity->hasField('field_c_b_link_in_mobile_menu') && civictheme_get_field_value($entity, 'field_c_b_link_in_mobile_menu')) { + if (civictheme_get_field_value($entity, 'field_c_b_link_in_mobile_menu')) { // Hide search block on mobile view. $variables['modifier_class'] = 'hide-xxs show-m-flex'; - $search_link = [ - 'url' => $link->getUrl()->toString(), - 'text' => $link->get('title')->getString(), - ]; - _civictheme_search_link($search_link); } } diff --git a/web/themes/contrib/civictheme/includes/utilities.inc b/web/themes/contrib/civictheme/includes/utilities.inc index 7552a8aefa..b8d94140fc 100644 --- a/web/themes/contrib/civictheme/includes/utilities.inc +++ b/web/themes/contrib/civictheme/includes/utilities.inc @@ -911,22 +911,3 @@ function _civictheme_feature_optout_flags(): array { $flags[CivicthemeConstants::OPTOUT_SUMMARY_HIDE_ELLIPSIS] = t('Hide card summary ellipsis'); return $flags; } - -/** - * Helper function to store and retrieve the search link. - * - * @param array|null $link - * The link array to store, or NULL to retrieve the stored link. - * - * @return array|null - * The stored link array, or NULL if no link is stored. - */ -function _civictheme_search_link(array $link = NULL): ?array { - static $stored_link = NULL; - - if ($link !== NULL) { - $stored_link = $link; - } - - return $stored_link; -}