/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $values = $form_state->getValues(); $new_settings = array(); // Store processor settings. // @todo Go through all available processors, enable/disable with method on // processor plugin to allow reaction. /** @var \Drupal\search_api\Processor\ProcessorInterface $processor */ $processors = $this->entity->getProcessors(FALSE); foreach ($processors as $processor_id => $processor) { if (empty($values['status'][$processor_id])) { continue; } $new_settings[$processor_id] = array('processor_id' => $processor_id, 'weights' => array(), 'settings' => array()); $processor_values = $values['processors'][$processor_id]; if (!empty($processor_values['weights'])) { $new_settings[$processor_id]['weights'] = $processor_values['weights']; } if (isset($form['settings'][$processor_id])) { $processor_form_state = new SubFormState($form_state, array('processors', $processor_id, 'settings')); $processor->submitConfigurationForm($form['settings'][$processor_id], $processor_form_state); $new_settings[$processor_id]['settings'] = $processor->getConfiguration(); } } // Sort the processors so we won't have unnecessary changes. ksort($new_settings); if (!$this->entity->getOption('processors', array()) !== $new_settings) { $this->entity->setOption('processors', $new_settings); $this->entity->save(); $this->entity->reindex(); drupal_set_message($this->t('The indexing workflow was successfully edited. All content was scheduled for reindexing so the new settings can take effect.')); } else { drupal_set_message($this->t('No values were changed.')); } }
/** * Performs setup tasks before each individual test method is run. * * Installs commonly used schemas and sets up a search server and an index, * with the specified processor enabled. * * @param string|null $processor * (optional) The plugin ID of the processor that should be set up for * testing. */ public function setUp($processor = NULL) { parent::setUp(); $this->installSchema('node', array('node_access')); $this->installSchema('search_api', array('search_api_item', 'search_api_task')); $server_name = $this->randomMachineName(); $this->server = Server::create(array( 'id' => strtolower($server_name), 'name' => $server_name, 'status' => TRUE, 'backend' => 'search_api_db', 'backend_config' => array( 'min_chars' => 3, 'database' => 'default:default', ), )); $this->server->save(); $index_name = $this->randomMachineName(); $this->index = Index::create(array( 'id' => strtolower($index_name), 'name' => $index_name, 'status' => TRUE, 'datasources' => array('entity:comment', 'entity:node'), 'server' => $server_name, 'tracker' => 'default', )); $this->index->setServer($this->server); $this->index->setOption('fields', array( 'entity:comment/subject' => array( 'type' => 'text', ), 'entity:node/title' => array( 'type' => 'text', ), )); if ($processor) { $this->index->setOption('processors', array( $processor => array( 'processor_id' => $processor, 'weights' => array(), 'settings' => array(), ), )); /** @var \Drupal\search_api\Processor\ProcessorPluginManager $plugin_manager */ $plugin_manager = \Drupal::service('plugin.manager.search_api.processor'); $this->processor = $plugin_manager->createInstance($processor, array('index' => $this->index)); } $this->index->save(); \Drupal::configFactory() ->getEditable('search_api.settings') ->set('tracking_page_size', 100) ->save(); Utility::getIndexTaskManager()->addItemsAll($this->index); }
/** * {@inheritdoc} */ public function setOption($name, $option) { $this->changedProperties['options'] = 'options'; return $this->entity->setOption($name, $option); }