3 namespace Drupal\form_test\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Form to test page cache storage.
13 class FormTestStoragePageCacheForm extends FormBase {
18 public function getFormId() {
19 return 'form_test_storage_page_cache';
25 public function buildForm(array $form, FormStateInterface $form_state) {
27 '#type' => 'textfield',
32 $form['test_build_id_old'] = [
34 '#title' => 'Old build id',
35 '#markup' => 'No old build id',
45 '#value' => 'Rebuild',
46 '#submit' => [[$this, 'form_test_storage_page_cache_rebuild']],
49 $form['#after_build'] = [[$this, 'form_test_storage_page_cache_old_build_id']];
55 * Form element #after_build callback: output the old form build-id.
57 public function form_test_storage_page_cache_old_build_id($form) {
58 if (isset($form['#build_id_old'])) {
59 $form['test_build_id_old']['#plain_text'] = $form['#build_id_old'];
65 * Form submit callback: Rebuild the form and continue.
67 public function form_test_storage_page_cache_rebuild($form, FormStateInterface $form_state) {
68 $form_state->setRebuild();
74 public function validateForm(array &$form, FormStateInterface $form_state) {
75 // Test using form cache when re-displaying a form due to validation
77 if ($form_state->hasAnyErrors()) {
78 $form_state->setCached();
85 public function submitForm(array &$form, FormStateInterface $form_state) {
86 // Nothing must happen.