Version 1
[yaffs-website] / web / core / modules / system / tests / modules / session_exists_cache_context_test / session_exists_cache_context_test.module
1 <?php
2
3 /**
4  * @file
5  * Test module.
6  */
7
8 /**
9  * Implements hook_page_top().
10  */
11 function session_exists_cache_context_test_page_top(array &$page_top) {
12   // Ensure this hook is invoked on every page load.
13   $page_top['#cache']['max-age'] = 0;
14
15   $request = \Drupal::request();
16   $session_exists = \Drupal::service('session_configuration')->hasSession($request);
17   $page_top['session_exists_cache_context_test'] = [
18     'label' => [
19       '#markup' => '<p>' . ($session_exists ? 'Session exists!' : 'Session does not exist!') . '</p>',
20     ],
21     'cache_context_value' => [
22       '#markup' => '<code>[session.exists]=' . \Drupal::service('cache_context.session.exists')->getContext() . '</code>',
23     ],
24   ];
25
26   if (\Drupal::request()->query->get('trigger_session')) {
27     $_SESSION['session_exists_cache_context_test'] = TRUE;
28   }
29 }