function FormStatePersistTest::displayCachedState

Render API #post_render callback.

After form is rendered, add status messages displaying form state 'processed_value' and 'rebuilt_value'.

Attributes

#[TrustedCallback]

File

core/modules/system/tests/src/Kernel/Form/FormStatePersistTest.php, line 107

Class

FormStatePersistTest
Tests that the form state persists across multiple requests.

Namespace

Drupal\Tests\system\Kernel\Form

Code

public static function displayCachedState(string $rendered_form, array $form) : string {
  $form_state = new FormState();
  \Drupal::formBuilder()->getCache($form['#build_id'], $form_state);
  // Save the values retrieved from form state storage during post render, so
  // the values can be confirmed in test assertions.
  static::$postRenderStoragePersist['process'] = (bool) $form_state->get('process');
  static::$postRenderStoragePersist['rebuild'] = (bool) $form_state->get('rebuild');
  return $rendered_form;
}

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