IndexSolrMultisiteUpdateForm.php in Search API Solr 4.x
File
src/Form/IndexSolrMultisiteUpdateForm.php
View source
<?php
namespace Drupal\search_api_solr\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\search_api\Form\IndexForm;
class IndexSolrMultisiteUpdateForm extends IndexSolrMultisiteCloneForm {
public function form(array $form, FormStateInterface $form_state) {
if ($form_state
->isRebuilding()) {
if (!$this->entity
->isNew()) {
$form_state
->setValue('id', $this->entity
->id());
}
$this->entity = $this
->buildEntity($form, $form_state);
}
if (!$this->entity
->isNew()) {
$server = $this->entity
->getServerInstance();
$backend = $server
->getBackend();
$datasource = $this->entity
->getDatasource('solr_multisite_document');
$target_index = $this->entityTypeManager
->getStorage('search_api_index')
->load($datasource
->getConfiguration()['target_index_machine_name']);
$fields = $target_index
->getFields();
$solr_field_names = $backend
->getSolrFieldNames($target_index);
foreach ($fields as $field_id => $field) {
$field
->setDatasourceId('solr_multisite_document');
$field
->setConfiguration([]);
$field
->setPropertyPath($solr_field_names[$field_id]);
}
$this->entity
->setFields($fields);
$this->entity
->setProcessors($target_index
->getProcessors());
$target_index_prefixed = $backend
->getTargetedIndexId($target_index);
}
$form = IndexForm::form($form, $form_state);
$arguments = [
'%label' => $this->entity
->label(),
];
$form['#title'] = $this
->t('Update multisite search index %label', $arguments);
$this
->buildEntityForm($form, $form_state, $this->entity);
$form['datasource_configs']['solr_multisite_document']['target_index']['#default_value'] = $target_index_prefixed;
return $form;
}
}