You are here

function install_get_form in Drupal 8

Same name and namespace in other branches
  1. 9 core/includes/install.core.inc \install_get_form()

Builds and processes a form for the installer environment.

Ensures that FormBuilder does not redirect after submitting a form, since the installer uses a custom step/flow logic via install_run_tasks().

Parameters

string|array $form_id: The form ID to build and process.

array $install_state: The current state of the installation.

Return value

array|null A render array containing the form to render, or NULL in case the form was successfully submitted.

Throws

\Drupal\Core\Installer\Exception\InstallerException

3 calls to install_get_form()
install_run_task in core/includes/install.core.inc
Runs an individual installation task.
install_select_language in core/includes/install.core.inc
Selects which language to use during installation.
install_select_profile in core/includes/install.core.inc
Selects which profile to install.

File

core/includes/install.core.inc, line 940
API functions for installing Drupal.

Code

function install_get_form($form_id, array &$install_state) {

  // Ensure the form will not redirect, since install_run_tasks() uses a custom
  // redirection logic.
  $form_state = (new FormState())
    ->addBuildInfo('args', [
    &$install_state,
  ])
    ->disableRedirect();
  $form_builder = \Drupal::formBuilder();
  if ($install_state['interactive']) {
    $form = $form_builder
      ->buildForm($form_id, $form_state);

    // If the form submission was not successful, the form needs to be rendered,
    // which means the task is not complete yet.
    if (!$form_state
      ->isExecuted()) {
      $install_state['task_not_complete'] = TRUE;
      return $form;
    }
  }
  else {

    // For non-interactive installs, submit the form programmatically with the
    // values taken from the installation state.
    $install_form_id = $form_builder
      ->getFormId($form_id, $form_state);
    if (!empty($install_state['forms'][$install_form_id])) {
      $form_state
        ->setValues($install_state['forms'][$install_form_id]);
    }
    $form_builder
      ->submitForm($form_id, $form_state);

    // Throw an exception in case of any form validation error.
    if ($errors = $form_state
      ->getErrors()) {
      throw new InstallerException(implode("\n", $errors));
    }
  }
}