3 namespace Drupal\form_test\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
8 class FormTestStoragePageCacheForm extends FormBase {
13 public function getFormId() {
14 return 'form_test_storage_page_cache';
20 public function buildForm(array $form, FormStateInterface $form_state) {
22 '#type' => 'textfield',
27 $form['test_build_id_old'] = [
29 '#title' => 'Old build id',
30 '#markup' => 'No old build id',
40 '#value' => 'Rebuild',
41 '#submit' => [[$this, 'form_test_storage_page_cache_rebuild']],
44 $form['#after_build'] = [[$this, 'form_test_storage_page_cache_old_build_id']];
50 * Form element #after_build callback: output the old form build-id.
52 public function form_test_storage_page_cache_old_build_id($form) {
53 if (isset($form['#build_id_old'])) {
54 $form['test_build_id_old']['#plain_text'] = $form['#build_id_old'];
60 * Form submit callback: Rebuild the form and continue.
62 public function form_test_storage_page_cache_rebuild($form, FormStateInterface $form_state) {
63 $form_state->setRebuild();
69 public function validateForm(array &$form, FormStateInterface $form_state) {
70 // Test using form cache when re-displaying a form due to validation
72 if ($form_state->hasAnyErrors()) {
73 $form_state->setCached();
80 public function submitForm(array &$form, FormStateInterface $form_state) {
81 // Nothing must happen.