You are here

public function ServerForm::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/ServerForm.php, line 64

Class

ServerForm
Provides a form for creating and editing search servers.

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()) {
    $this->entity = $this
      ->buildEntity($form, $form_state);
  }
  $form = parent::form($form, $form_state);

  /** @var \Drupal\search_api\ServerInterface $server */
  $server = $this
    ->getEntity();

  // Set the page title according to whether we are creating or editing the
  // server.
  if ($server
    ->isNew()) {
    $form['#title'] = $this
      ->t('Add search server');
  }
  else {
    $form['#title'] = $this
      ->t('Edit search server %label', [
      '%label' => $server
        ->label(),
    ]);
  }
  $this
    ->buildEntityForm($form, $form_state, $server);

  // Skip adding the backend config form if we cleared the server form due to
  // an error.
  if ($form) {
    $this
      ->buildBackendConfigForm($form, $form_state, $server);
  }
  return $form;
}