forked from amcgowanca/shield_agent
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshield_agent.module
More file actions
33 lines (29 loc) · 880 Bytes
/
shield_agent.module
File metadata and controls
33 lines (29 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
* @file
* Provides the ability for securing a Drupal 8 application and locking down various routes.
*/
/**
* Implements hook_preprocess().
*/
function shield_agent_preprocess(&$variables, $hook) {
if (isset($variables['element']['#cache'])) {
_shield_agent_attach_environment_cache_context($variables['element']);
}
elseif (isset($variables['#cache'])) {
_shield_agent_attach_environment_cache_context($variables);
}
}
/**
* Attaches the Shield Agent Environment cache context.
*
* @param array $element
* The element to modify and attach the Shield Agent Environment context to.
*/
function _shield_agent_attach_environment_cache_context(array &$element) {
if (!isset($element['#cache'])) {
$element['#cache'] = [];
}
$element['#cache'] += ['contexts' => []];
$element['#cache']['contexts'][] = 'shield_agent_environment';
}