Undefined array key "synonyms" in ElasticSearchBackend->buildConfigurationForm()

Created on 31 October 2024, 6 months ago

Problem/Motivation

After migrating data from elasticsearch_connector-8.x-7.x, on the configuration page at /admin/config/search/search-api/server/onesite_elasticsearch_server/edit, I get the following warning...

Warning: Undefined array key "synonyms" in Drupal\elasticsearch_connector\Plugin\search_api\backend\ElasticSearchBackend->buildConfigurationForm() (line 195 of modules/contrib/elasticsearch_connector/src/Plugin/search_api/backend/ElasticSearchBackend.php)

... the line in question looks like...

      '#default_value' => implode(\PHP_EOL, (array) $this->configuration['advanced']['synonyms'] ?? []),

My IDE hints that there may be missing parentheses on that line, because operator precedence rules say that type-casting happens before null coalescing, i.e.: (array) $this->configuration['advanced']['synonyms'] gets evaluated first (resulting in the warning), followed by $resulting_array ?? [] (which will always evaluate to $resulting_array).

Proposed resolution

Double-check the intent of that line, and add parentheses if that will fix the problem.

Remaining tasks

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

User interface changes

None.

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