"Fields to highlight field is required" even when Elasticsearch Highlighter is disabled

Created on 27 February 2025, about 1 month ago

Problem/Motivation

I noticed in 📌 The whole index gets cleared when any change in the search index configuration is imported Active , the test in Drupal\Tests\elasticsearch_connector\Functional\ManualConfigIndexTest::testIndexIntactAfterNoChange started failing after Highlighting support (leverage Elasticsearch highlighting) Needs review .

Investigating, it seems like trying to save the Manage processors for search index form at /admin/config/search/search-api/index/INDEX_NAME/processors was failing to validate with the following error:

Fields to highlight field is required

When I made the field not-required to test...

diff --git a/src/Plugin/search_api/processor/ElasticsearchHighlighter.php b/src/Plugin/search_api/processor/ElasticsearchHighlighter.php
index 364112e..fcef094 100644
--- a/src/Plugin/search_api/processor/ElasticsearchHighlighter.php
+++ b/src/Plugin/search_api/processor/ElasticsearchHighlighter.php
@@ -45,7 +45,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
       '#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,
+      '#required' => FALSE,
       '#multiple' => TRUE,
       '#options' => $this->getFieldOptions($this->index),
     ];

... the test passed, so that's the problem.

Steps to reproduce

(see description)

Proposed resolution

Make sure $form['fields'] is only required when the elasticsearch_highlight processor is active.

Remaining tasks

  1. Write a patch
  2. Review and feedback
  3. RTBC and feedback
  4. Commit
  5. Release

User interface changes

The "Elasticsearch Highlighter" processor's "Fields to highlight" field is only required when the processor is enabled.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

8.0

Component

Code

Created by

🇨🇦Canada mparker17 UTC-4

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024