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

OEL-3411: Set default button label in search block header, if not already set. #314

Open
wants to merge 6 commits into
base: 1.x
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: 1 addition & 1 deletion config/optional/block.block.oe_whitelabel_search_form.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ settings:
label: Search
placeholder: Search
button:
label: ''
label: Search
view_options:
enable_autocomplete: false
id: null
Expand Down
26 changes: 26 additions & 0 deletions modules/oe_whitelabel_search/oe_whitelabel_search.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,29 @@ function oe_whitelabel_search_post_update_00001(&$sandbox) {
$block->set('settings', $settings);
$block->save();
}

/**
* Set default button label in search block if it's not already set.
*/
function oe_whitelabel_search_post_update_00002(&$sandbox) {
$theme_manager = \Drupal::service('theme.manager');
$current_theme = $theme_manager->getActiveTheme()->getName();

$block_storage = \Drupal::entityTypeManager()->getStorage('block');
$blocks = $block_storage->loadByProperties(['theme' => $current_theme, 'plugin' => 'whitelabel_search_block']);

$updated_blocks = [];
foreach ($blocks as $block) {
$settings = $block->get('settings');
if (empty($settings['button']['label'])) {
$settings['button']['label'] = t('Search');
$block->set('settings', $settings);
$block->save();
$updated_blocks[] = $block->id();
}
}
if (!empty($updated_blocks)) {
return 'The following search blocks have been updated: ' . implode(', ', $updated_blocks);
}
return 'No search block needed to be updated.';
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function defaultConfiguration() {
'placeholder' => $this->t('Search'),
],
'button' => [
'label' => '',
'label' => $this->t('Search'),
],
'view_options' => [
'enable_autocomplete' => FALSE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
* @see ./core/modules/system/templates/input.html.twig
*/
#}
{% if element['#value'] is not empty %}
{% set label %}
<span class="d-none d-lg-inline-block">{{ element['#value']|t }}</span>
{% endset %}
{% endif %}
{{ pattern('button', {
'variant': 'light',
'label': label,
'label': element['#value']|t,
'icon': 'search',
'type': 'submit',
'icon_position': 'before',
Expand Down