function install_get_form
Same name in other branches
- 9 core/includes/install.core.inc \install_get_form()
- 8.9.x core/includes/install.core.inc \install_get_form()
- 11.x 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 962
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])) {
$values = $install_state['forms'][$install_form_id];
if ($install_form_id === 'install_settings_form' && isset($values['driver']) && !str_contains($values['driver'], "\\")) {
@trigger_error("Passing a database driver name '{$values['driver']}' to " . __FUNCTION__ . '() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Pass a database driver namespace instead. See https://www.drupal.org/node/3258175', E_USER_DEPRECATED);
$driverExtension = Database::getDriverList()->getFromDriverName($values['driver']);
$tmp = [];
$tmp['driver'] = $driverExtension->getName();
$tmp[$driverExtension->getName()] = $values[$values['driver']];
$values = $tmp;
}
$form_state->setValues($values);
}
$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));
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.