Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit f73a1546 authored by drishu's avatar drishu
Browse files

OEL-601: Remove config, add cache meta.

parent d03a1781
No related branches found
No related tags found
1 merge request!38OEL-601: Theming search box button with icon
......@@ -29,12 +29,6 @@ block.settings.whitelabel_search_block:
type: mapping
label: Button
mapping:
label:
type: string
label: Label
label_icon:
type: string
label: Label and Icon
classes:
type: string
label: Classes
......
......@@ -81,6 +81,10 @@ class SearchForm extends FormBase {
'#id' => 'button',
'#variant' => 'light',
'#fields' => [
'icon' => [
'name' => 'search',
'size' => 'xs',
],
'settings' => [
'type' => 'submit',
],
......@@ -99,16 +103,6 @@ class SearchForm extends FormBase {
],
];
if ($config['button']['label_icon'] != 'icon') {
$form['submit']['#fields']['label'] = $config['button']['label'];
}
if ($config['button']['label_icon'] != 'label') {
$form['submit']['#fields']['icon'] = [
'name' => 'search',
'size' => 'xs',
];
}
if (!$config['view_options']['enable_autocomplete']) {
return $form;
}
......
......@@ -6,6 +6,7 @@ namespace Drupal\oe_whitelabel_search\Plugin\Block;
use Drupal\Component\Utility\Html;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormBuilderInterface;
......@@ -138,24 +139,6 @@ class SearchBlock extends BlockBase implements ContainerFactoryPluginInterface {
'#tree' => TRUE,
'#description' => $this->t('Fill in the settings of the Button field.'),
];
$form['button']['button_label'] = [
'#type' => 'textfield',
'#title' => $this->t('Button label'),
'#description' => $this->t('Label text that should appear inside the button.'),
'#default_value' => $config['button']['label'],
'#required' => TRUE,
];
$form['button']['button_label_icon'] = [
'#type' => 'radios',
'#default_value' => isset($config['button']['label_icon']) ? $config['button']['label_icon'] : 'icon',
'#options' => [
'label' => $this->t('Label'),
'icon' => $this->t('Icon'),
'label_icon' => $this->t('Label and icon'),
],
'#title' => $this->t('Button display options'),
];
$form['button']['button_classes'] = [
'#type' => 'textfield',
'#title' => $this->t('Button classes'),
......@@ -219,7 +202,7 @@ class SearchBlock extends BlockBase implements ContainerFactoryPluginInterface {
$button = $values['button'];
$this->setConfigurationValue('button', [
'label' => $button['button_label'],
'label_icon' => $button['button_label_icon'],
'display' => $button['button_display'],
'classes' => $button['button_classes'],
]);
$this->setConfigurationValue('view_options', [
......@@ -270,7 +253,14 @@ class SearchBlock extends BlockBase implements ContainerFactoryPluginInterface {
* {@inheritdoc}
*/
public function build(): array {
return $this->formBuilder->getForm(SearchForm::class, $this->getConfiguration());
$config = $this->getConfiguration();
$build = $this->formBuilder->getForm(SearchForm::class, $config);
$cache = CacheableMetadata::createFromRenderArray($build);
$cache->addCacheableDependency($config);
$cache->addCacheContexts(['url.query_args']);
$cache->applyTo($build);
return $build;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment