diff --git a/src/Plugin/search_api/processor/ElasticsearchHighlighter.php b/src/Plugin/search_api/processor/ElasticsearchHighlighter.php index 364112ef0577eaba1840e7026368cdf5a7317a0d..5ad1be2b64203f006c77760ebcaf41d0ac236e57 100644 --- a/src/Plugin/search_api/processor/ElasticsearchHighlighter.php +++ b/src/Plugin/search_api/processor/ElasticsearchHighlighter.php @@ -45,9 +45,13 @@ class ElasticsearchHighlighter extends ProcessorPluginBase implements PluginForm '#title' => $this->t('Fields to highlight'), '#description' => $this->t('The fields to search for highlights in, and to display highlights for.'), '#default_value' => $config['fields'], - '#required' => TRUE, '#multiple' => TRUE, '#options' => $this->getFieldOptions($this->index), + '#states' => [ + 'required' => [ + ':input[name="status[elasticsearch_highlight]"]' => ['checked' => TRUE], + ], + ], ]; $form['help_terms'] = [ @@ -59,11 +63,15 @@ class ElasticsearchHighlighter extends ProcessorPluginBase implements PluginForm '#type' => 'radios', '#title' => $this->t('Highlighter type'), '#default_value' => $config['type'], - '#required' => TRUE, '#options' => [ 'unified' => $this->t('Unified'), 'plain' => $this->t('Plain'), ], + '#states' => [ + 'required' => [ + ':input[name="status[elasticsearch_highlight]"]' => ['checked' => TRUE], + ], + ], ]; $form['type']['unified']['#description'] = $this->t('Better when highlighting fields that contain HTML, or a mixture of plain-text fields and HTML fields.'); $form['type']['plain']['#description'] = $this->t('Faster when highlighting fields that do not contain HTML.'); @@ -139,14 +147,17 @@ class ElasticsearchHighlighter extends ProcessorPluginBase implements PluginForm '@strong_html_tag' => '<strong>', '@mark_html_tag' => '<mark>', ]), - '#required' => TRUE, + '#states' => [ + 'required' => [ + ':input[name="status[elasticsearch_highlight]"]' => ['checked' => TRUE], + ], + ], ]; $form['encoder'] = [ '#type' => 'radios', '#title' => $this->t('Snippet encoder'), '#default_value' => $config['encoder'], - '#required' => TRUE, '#options' => [ 'default' => $this->t('No encoding'), 'html' => $this->t('HTML'), @@ -154,6 +165,11 @@ class ElasticsearchHighlighter extends ProcessorPluginBase implements PluginForm '#description' => $this->t("ElasticSearch doesn't natively provide a way to remove HTML tags, only escape them. The ElasticSearch Connector module's post-processor strips out any HTML tags that are not the highlighting tag to avoid invalid HTML in snippets, so %default_option is safe to use and usually produces the results you would expect.", [ '%default_option' => $this->t('No encoding'), ]), + '#states' => [ + 'required' => [ + ':input[name="status[elasticsearch_highlight]"]' => ['checked' => TRUE], + ], + ], ]; $form['encoder']['default']['#description'] = $this->t('Simply insert the highlight tags without making any changes to the snippet.'); $form['encoder']['html']['#description'] = $this->t('Escape HTML in the snippet (i.e.: making the HTML tags in the field visible), before inserting the highlight tags.'); @@ -190,11 +206,15 @@ class ElasticsearchHighlighter extends ProcessorPluginBase implements PluginForm '#type' => 'radios', '#title' => $this->t('Snippet order'), '#default_value' => $config['order'], - '#required' => TRUE, '#options' => [ 'none' => $this->t('Order snippets by the order they appear in the field'), 'score' => $this->t('Order snippets so the most relevant snippets are first'), ], + '#states' => [ + 'required' => [ + ':input[name="status[elasticsearch_highlight]"]' => ['checked' => TRUE], + ], + ], ]; $form['require_field_match'] = [