Skip to content

Commit

Permalink
[CIVIC-2042] Fixed CR.
Browse files Browse the repository at this point in the history
  • Loading branch information
febdao committed Mar 7, 2025
1 parent 15cf327 commit 322e4e2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 24 additions & 3 deletions web/themes/contrib/civictheme/includes/mobile_navigation.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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'],
Expand Down
7 changes: 1 addition & 6 deletions web/themes/contrib/civictheme/includes/search.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
19 changes: 0 additions & 19 deletions web/themes/contrib/civictheme/includes/utilities.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 322e4e2

Please sign in to comment.