install_get_form($form_id, array &$install_state)
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
File
- core/includes/install.core.inc, line 884
- API functions for installing Drupal.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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 )); } } } |
Please login to continue.