-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcypress.module
38 lines (35 loc) · 1.02 KB
/
cypress.module
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
34
35
36
37
38
<?php
/**
* Check if cypress helpers are enabled.
*
* @return bool
*/
function cypress_enabled() {
return \Drupal::getContainer()->getParameter('cypress.enabled');
}
/**
* Implements hook_module_implements_alter().
*/
function cypress_module_implements_alter(&$implementations, $hook) {
// Make sure our hooks run last.
if (in_array($hook, ['page_top'])) {
$group = $implementations['cypress'];
unset($implementations['cypress']);
$implementations['cypress'] = $group;
}
}
/**
* Disable the admin toolbar by default, since it often.
*
* Often interferes with cypress click handling. Can be enabled by setting the
* `X-CYPRESS-TOOLBAR` request header.
*
* @param array $page_top
*/
function cypress_page_top(array &$page_top) {
/** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $session */
$session = \Drupal::service('session');
if (cypress_enabled() && !($session->has('CYPRESS_TOOLBAR') || \Drupal::request()->headers->has('X-CYPRESS-TOOLBAR'))) {
unset($page_top['toolbar']);
}
}