FormState::$cache

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Form/FormState.php \Drupal\Core\Form\FormState::cache
  2. 8.9.x core/lib/Drupal/Core/Form/FormState.php \Drupal\Core\Form\FormState::cache
  3. 10 core/lib/Drupal/Core/Form/FormState.php \Drupal\Core\Form\FormState::cache

Determines if the unprocessed form structure is cached.

If set to TRUE the original, unprocessed form structure will be cached, which allows the entire form to be rebuilt from cache. A typical form workflow involves two page requests; first, a form is built and rendered for the user to fill in. Then, the user fills the form in and submits it, triggering a second page request in which the form must be built and processed. By default, $form and $form_state are built from scratch during each of these page requests. Often, it is necessary or desired to persist the $form and $form_state variables from the initial page request to the one that processes the submission. 'cache' can be set to TRUE to do this. A prominent example is an Ajax-enabled form, in which \Drupal\Core\Render\Element\RenderElementBase::processAjaxForm() enables form caching for all forms that include an element with the #ajax property. (The Ajax handler has no way to build the form itself, so must rely on the cached version.) Note that the persistence of $form and $form_state happens automatically for (multi-step) forms having the self::$rebuild flag set, regardless of the value for self::$cache.

Type: bool

File

core/lib/Drupal/Core/Form/FormState.php, line 221

Class

FormState
Stores information about the state of a form.

Namespace

Drupal\Core\Form

Code

protected $cache = FALSE;

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