5 * Provides functionality for testing form caching.
8 use Drupal\Core\Form\FormStateInterface;
11 * Implements hook_form_FORM_ID_alter().
13 function page_cache_form_test_form_page_cache_form_test_alter(&$form, FormStateInterface $form_state, $form_id) {
14 // This runs earlier than system_form_alter() so we fore-go the immutability
15 // check to the process callback, by which time system_form_alter() has run.
16 $form['#process'][] = 'page_cache_form_test_form_page_cache_form_test_process';
20 * Process callback to check immutability.
22 function page_cache_form_test_form_page_cache_form_test_process($form, FormStateInterface $form_state) {
23 if (isset($form_state->getBuildInfo()['immutable']) && $form_state->getBuildInfo()['immutable']) {
24 $form['#suffix'] = 'Immutable: TRUE';
27 $form['#suffix'] = 'Immutable: FALSE';
33 * Implements hook_module_implements_alter().
35 function page_cache_form_test_module_implements_alter(&$implementations, $hook) {
36 if ($hook === 'form_alter' && \Drupal::state()->get('page_cache_bypass_form_immutability', FALSE)) {
37 // Disable system_form_alter
38 unset($implementations['system']);