You are here

public function IndexStatusForm::submitForm in Search API 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/IndexStatusForm.php, line 239

Class

IndexStatusForm
Provides a form for indexing, clearing, etc., an index.

Namespace

Drupal\search_api\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\search_api\IndexInterface $index */
  $index = $form['#index'];
  switch ($form_state
    ->getTriggeringElement()['#name']) {
    case 'index_now':
      $values = $form_state
        ->getValues();
      try {
        IndexBatchHelper::setStringTranslation($this
          ->getStringTranslation());
        IndexBatchHelper::create($index, $values['batch_size'], $values['limit']);
      } catch (SearchApiException $e) {
        $this->messenger
          ->addWarning($this
          ->t('Failed to create a batch, please check the batch size and limit.'));
      }
      break;
    case 'reindex':
      $form_state
        ->setRedirect('entity.search_api_index.reindex', [
        'search_api_index' => $index
          ->id(),
      ]);
      break;
    case 'clear':
      $form_state
        ->setRedirect('entity.search_api_index.clear', [
        'search_api_index' => $index
          ->id(),
      ]);
      break;
    case 'rebuild_tracker':
      $form_state
        ->setRedirect('entity.search_api_index.rebuild_tracker', [
        'search_api_index' => $index
          ->id(),
      ]);
      break;
    case 'track_now':
      $this
        ->getIndexTaskManager()
        ->addItemsBatch($index);
      break;
  }
}