You are here

public function IndexForm::form in Search API 8

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/IndexForm.php, line 107

Class

IndexForm
Provides a form for the Index entity.

Namespace

Drupal\search_api\Form

Code

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

  // If the form is being rebuilt, rebuild the entity with the current form
  // values.
  if ($form_state
    ->isRebuilding()) {

    // When the form is being built for an AJAX response the ID is not present
    // in $form_state. To ensure our entity is always valid, we're adding the
    // ID back.
    if (!$this->entity
      ->isNew()) {
      $form_state
        ->setValue('id', $this->entity
        ->id());
    }
    $this->entity = $this
      ->buildEntity($form, $form_state);
  }
  $form = parent::form($form, $form_state);

  /** @var \Drupal\search_api\IndexInterface $index */
  $index = $this
    ->getEntity();
  if ($index
    ->isNew()) {
    $form['#title'] = $this
      ->t('Add search index');
  }
  else {
    $arguments = [
      '%label' => $index
        ->label(),
    ];
    $form['#title'] = $this
      ->t('Edit search index %label', $arguments);
  }
  $this
    ->buildEntityForm($form, $form_state, $index);
  return $form;
}