You are here

public function ServerForm::buildBackendConfigForm in Search API 8

Builds the backend-specific configuration form.

Parameters

array $form: The current form array.

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

\Drupal\search_api\ServerInterface $server: The server that is being created or edited.

1 call to ServerForm::buildBackendConfigForm()
ServerForm::form in src/Form/ServerForm.php
Gets the actual form array to be built.

File

src/Form/ServerForm.php, line 211

Class

ServerForm
Provides a form for creating and editing search servers.

Namespace

Drupal\search_api\Form

Code

public function buildBackendConfigForm(array &$form, FormStateInterface $form_state, ServerInterface $server) {
  $form['backend_config'] = [];
  if ($server
    ->hasValidBackend()) {
    $backend = $server
      ->getBackend();
    $form_state
      ->set('backend', $backend
      ->getPluginId());
    if ($backend instanceof PluginFormInterface) {
      if ($form_state
        ->isRebuilding()) {
        $this->messenger
          ->addWarning($this
          ->t('Please configure the selected backend.'));
      }

      // Attach the backend plugin configuration form.
      $backend_form_state = SubformState::createForSubform($form['backend_config'], $form, $form_state);
      $form['backend_config'] = $backend
        ->buildConfigurationForm($form['backend_config'], $backend_form_state);

      // Modify the backend plugin configuration container element.
      $form['backend_config']['#type'] = 'details';
      $form['backend_config']['#title'] = $this
        ->t('Configure %plugin backend', [
        '%plugin' => $backend
          ->label(),
      ]);
      $form['backend_config']['#open'] = TRUE;
    }
  }
  elseif (!$server
    ->isNew()) {
    $this->messenger
      ->addError($this
      ->t('The backend plugin is missing or invalid.'));
    return;
  }
  $form['backend_config'] += [
    '#type' => 'container',
  ];
  $form['backend_config']['#attributes']['id'] = 'search-api-backend-config-form';
  $form['backend_config']['#tree'] = TRUE;
}