Skip to content

Commit

Permalink
Issue #3486761 by scott_euser, mkalkbrenner: Prepare for updated add …
Browse files Browse the repository at this point in the history
…fields to index UI
  • Loading branch information
mkalkbrenner committed Nov 25, 2024
1 parent 5701bb4 commit 5eac976
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 53 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"conflict": {
"drupal/acquia_search_solr": "<1.0.0-beta8",
"drupal/search_api_autocomplete": "<1.6.0",
"drupal/search_api_solr_multilingual": "<3.0.0"
"drupal/search_api_solr_multilingual": "<3.0.0",
"drupal/search_api": "<1.36"
},
"suggest": {
"drupal/facets": "Provides facetted search.",
Expand Down
2 changes: 1 addition & 1 deletion search_api_solr.module
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ function search_api_solr_form_search_api_index_fields_alter(&$form, FormStateInt
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 700,
'width' => '90%',
]),
],
'#weight' => -10,
Expand Down
70 changes: 19 additions & 51 deletions src/Form/IndexAddSolrDocumentFieldsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

namespace Drupal\search_api_solr\Form;

use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\search_api\Form\IndexAddFieldsForm;
use Drupal\search_api_solr\Plugin\search_api\datasource\SolrDocument;
use Drupal\search_api_solr\Plugin\search_api\datasource\SolrMultisiteDocument;

/**
* Provides a form for adding fields to a search index.
Expand All @@ -25,25 +21,7 @@ public function getFormId() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$index = $this->entity;

// Do not allow the form to be cached. See
// \Drupal\views_ui\ViewEditForm::form().
$form_state->disableCache();

$this->checkEntityEditable($form, $index);

$args['%index'] = $index->label();
$form['#title'] = $this->t('Add fields to index %index', $args);

$this->formIdAttribute = Html::getUniqueId($this->getFormId());
$form['#id'] = $this->formIdAttribute;

$form['messages'] = [
'#type' => 'status_messages',
];

protected function buildDatasourcesForm(array $form, FormStateInterface $form_state): array {
$datasources = [
'' => NULL,
];
Expand All @@ -52,40 +30,30 @@ public function buildForm(array $form, FormStateInterface $form_state) {
if ($datasource instanceof SolrDocument) {
$item = $this->getDatasourceListItem($datasource);
if ($item) {
foreach ($index->getFieldsByDatasource($datasource_id) as $field) {
unset($item[$field->getPropertyPath()]);
foreach ($this->entity->getFieldsByDatasource($datasource_id) as $field) {
if (empty($item['table']['#rows'])) {
continue;
}
$property = $field->getPropertyPath();

// Fields to add are stored in rows with the machine name column
// matching the field property. Remove any table rows that have
// already been added.
foreach ($item['table']['#rows'] as $key => $row) {
if (empty($row['machine_name']['data'])) {
continue;
}

if ($row['machine_name']['data'] === $property) {
unset($item['table']['#rows'][$key]);
}
}
}

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

$form['actions'] = $this->actionsElement($form, $form_state);

// Log any unmapped types that were encountered.
if ($this->unmappedFields) {
$unmapped_fields = [];
foreach ($this->unmappedFields as $type => $fields) {
foreach ($fields as $field) {
$unmapped_fields[] = new FormattableMarkup('@field (type "@type")', [
'@field' => $field,
'@type' => $type,
]);
}
}
$form['unmapped_types'] = [
'#type' => 'details',
'#title' => $this->t('Skipped fields'),
'fields' => [
'#theme' => 'item_list',
'#items' => $unmapped_fields,
'#prefix' => $this->t('The following fields cannot be indexed since there is no type mapping for them:'),
'#suffix' => $this->t("If you think one of these fields should be available for indexing, please report this in the module's <a href=':url'>issue queue</a>. (Make sure to first search for an existing issue for this field.) Please note that entity-valued fields generally can be indexed by either indexing their parent reference field, or their child entity ID field.", [':url' => Url::fromUri('https://www.drupal.org/project/issues/search_api')->toString()]),
],
];
}

return $form;
}

Expand Down

0 comments on commit 5eac976

Please sign in to comment.