Fix code of IndexAddSolrDocumentFieldsForm::buildForm()

Created on 17 April 2024, 8 months ago
Updated 6 May 2024, 8 months ago

The code for \Drupal\search_api_solr\Form\IndexAddSolrDocumentFieldsForm::buildForm() currently contains this:

      if ($datasource instanceof SolrDocument || $datasource instanceof SolrMultisiteDocument) {
        $item = $this->getDatasourceListItem($datasource);
        if ($item) {
          foreach ($index->getFields() as $field) {
            $id = $field->getFieldIdentifier();
            if (isset($item[$id])) {
              unset($item[$id]);
            }
          }

          $form['datasources']['datasource_' . $datasource_id] = $item;
        }
      }

This code has two problems:

  1. SolrMultisiteDocument is a subclass of SolrDocument, so the second check is unnecessary.
  2. The entries in $item are keyed by property path, not field identifier. While the field ID defaults to the property path (resp. its last component, in the general case), it can be changed so they donโ€™t always have to match.
๐Ÿ› Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

๐Ÿ‡ฆ๐Ÿ‡นAustria drunken monkey Vienna, Austria

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

Comments & Activities

Production build 0.71.5 2024