function FormBuilderInterface::rebuildForm

Same name in other branches
  1. 9 core/lib/Drupal/Core/Form/FormBuilderInterface.php \Drupal\Core\Form\FormBuilderInterface::rebuildForm()
  2. 8.9.x core/lib/Drupal/Core/Form/FormBuilderInterface.php \Drupal\Core\Form\FormBuilderInterface::rebuildForm()
  3. 11.x core/lib/Drupal/Core/Form/FormBuilderInterface.php \Drupal\Core\Form\FormBuilderInterface::rebuildForm()

Constructs a new $form from the information in $form_state.

This is the key function for making multi-step forms advance from step to step. It is called by self::processForm() when all user input processing, including calling validation and submission handlers, for the request is finished. If a validate or submit handler set $form_state->isRebuilding() to TRUE, and if other conditions don't preempt a rebuild from happening, then this function is called to generate a new $form, the next step in the form workflow, to be returned for rendering.

Ajax form submissions are almost always multi-step workflows, so that is one common use-case during which form rebuilding occurs.

Parameters

string $form_id: The unique string identifying the desired form. If a function with that name exists, it is called to build the form array.

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

array|null $old_form: (optional) A previously built $form. Used to retain the #build_id and #action properties in Ajax callbacks and similar partial form rebuilds. The only properties copied from $old_form are the ones which both exist in $old_form and for which $form_state->getRebuildInfo()['copy'][PROPERTY] is TRUE. If $old_form is not passed, the entire $form is rebuilt freshly. 'rebuild_info' needs to be a separate top-level property next to 'build_info', since the contained data must not be cached.

Return value

array The newly built form.

See also

self::processForm()

File

core/lib/Drupal/Core/Form/FormBuilderInterface.php, line 132

Class

FormBuilderInterface
Provides an interface for form building and processing.

Namespace

Drupal\Core\Form

Code

public function rebuildForm($form_id, FormStateInterface &$form_state, $old_form = NULL);

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.