Security update to Drupal 8.4.6
[yaffs-website] / web / core / modules / page_cache / tests / modules / page_cache_form_test.module
1 <?php
2
3 /**
4  * @file
5  * Provides functionality for testing form caching.
6  */
7
8 use Drupal\Core\Form\FormStateInterface;
9
10 /**
11 * Implements hook_form_FORM_ID_alter().
12 */
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';
17 }
18
19 /**
20  * Process callback to check immutability.
21  */
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';
25   }
26   else {
27     $form['#suffix'] = 'Immutable: FALSE';
28   }
29   return $form;
30 }
31
32 /**
33  * Implements hook_module_implements_alter().
34  */
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']);
39   }
40 }