Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIVIC-2089] Mobile search #1336

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions web/themes/contrib/civictheme/civictheme.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ config_devel:
- field.field.block_content.civictheme_mobile_navigation.field_c_b_trigger_text
- field.field.block_content.civictheme_mobile_navigation.field_c_b_trigger_theme
- field.field.block_content.civictheme_search.field_c_b_link
- field.field.block_content.civictheme_search.field_c_b_link_in_mobile_menu
- field.field.block_content.civictheme_social_links.field_c_b_social_icons
- field.field.block_content.civictheme_social_links.field_c_b_theme
- field.field.block_content.civictheme_social_links.field_c_b_with_border
Expand Down Expand Up @@ -472,6 +473,7 @@ config_devel:
- field.storage.block_content.field_c_b_components
- field.storage.block_content.field_c_b_featured_image
- field.storage.block_content.field_c_b_link
- field.storage.block_content.field_c_b_link_in_mobile_menu
- field.storage.block_content.field_c_b_social_icons
- field.storage.block_content.field_c_b_theme
- field.storage.block_content.field_c_b_top
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dependencies:
config:
- block_content.type.civictheme_search
- field.field.block_content.civictheme_search.field_c_b_link
- field.field.block_content.civictheme_search.field_c_b_link_in_mobile_menu
- workflows.workflow.civictheme_editorial
module:
- content_moderation
Expand All @@ -15,23 +16,30 @@ mode: default
content:
field_c_b_link:
type: link_default
weight: 26
weight: 1
region: content
settings:
placeholder_url: ''
placeholder_title: ''
third_party_settings: { }
field_c_b_link_in_mobile_menu:
type: boolean_checkbox
weight: 2
region: content
settings:
display_label: true
third_party_settings: { }
info:
type: string_textfield
weight: -5
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
moderation_state:
type: moderation_state_default
weight: 100
weight: 3
region: content
settings: { }
third_party_settings: { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dependencies:
config:
- block_content.type.civictheme_search
- field.field.block_content.civictheme_search.field_c_b_link
- field.field.block_content.civictheme_search.field_c_b_link_in_mobile_menu
module:
- link
id: block_content.civictheme_search.default
Expand All @@ -28,4 +29,14 @@ content:
third_party_settings: { }
weight: 0
region: content
field_c_b_link_in_mobile_menu:
type: boolean
label: above
settings:
format: default
format_custom_false: ''
format_custom_true: ''
third_party_settings: { }
weight: 1
region: content
hidden: { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
config:
- block_content.type.civictheme_search
- field.storage.block_content.field_c_b_link_in_mobile_menu
id: block_content.civictheme_search.field_c_b_link_in_mobile_menu
field_name: field_c_b_link_in_mobile_menu
entity_type: block_content
bundle: civictheme_search
label: 'Show link in mobile menu'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
on_label: 'On'
off_label: 'Off'
field_type: boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
langcode: en
status: true
dependencies:
module:
- block_content
id: block_content.field_c_b_link_in_mobile_menu
field_name: field_c_b_link_in_mobile_menu
entity_type: block_content
type: boolean
settings: { }
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
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
37 changes: 37 additions & 0 deletions web/themes/contrib/civictheme/includes/mobile_navigation.inc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ function _civictheme_preprocess_block__civictheme_mobile_navigation(array &$vari
'bottom_menu' => 'field_c_b_bottom',
];

// 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.
$entity_cache_tags = $entity->getCacheTags();
Expand Down Expand Up @@ -80,6 +104,19 @@ function _civictheme_preprocess_block__civictheme_mobile_navigation(array &$vari
$build = $menu_tree_service->build($tree);
$variables[$menu_key] = $build['#items'] ?? [];

// Add search link to end of top menu.
if ($menu_key === 'top_menu' && !empty($search_link)) {
$variables[$menu_key][] = [
'url' => $search_link['url'],
'title' => $search_link['text'],
'is_new_window' => FALSE,
'is_external' => FALSE,
'is_expanded' => FALSE,
'icon' => 'magnifier',
'below' => [],
];
}

_civictheme_preprocess_menu_items($variables[$menu_key], $expand_all_items);

$cacheability = $cacheability->merge(CacheableMetadata::createFromRenderArray($build));
Expand Down
4 changes: 4 additions & 0 deletions web/themes/contrib/civictheme/includes/search.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ function civictheme_preprocess_block__civictheme_search(array &$variables): void
if ($link !== NULL) {
$variables['url'] = $link->getUrl()->toString();
$variables['text'] = $link->get('title')->getString();
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';
}
}

$variables['theme'] = civictheme_get_theme_config_manager()->load('components.header.theme', CivicthemeConstants::HEADER_THEME_DEFAULT);
Expand Down