-
Notifications
You must be signed in to change notification settings - Fork 0
/
silverback_iframe.module
91 lines (80 loc) · 2.69 KB
/
silverback_iframe.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
use Drupal\silverback_iframe\WebformSubmissionForm;
use Drupal\webform\WebformInterface;
function silverback_iframe_inject_resizer() {
if (!getenv('SB_ENVIRONMENT')) {
return FALSE;
}
return \Drupal::request()->query->get('iframe_resizer') === 'true';
}
function silverback_iframe_theme_enabled() {
return \Drupal::request()->get('iframe') === 'true';
}
/**
* Implements hook_preprocess_HOOK().
*/
function silverback_iframe_preprocess_page(&$variables) {
$injectJs = FALSE;
$variables['page']['#cache']['contexts'][] = 'url.query_args:iframe';
if (silverback_iframe_theme_enabled()) {
$injectJs = TRUE;
}
if (getenv('SB_ENVIRONMENT')) {
$variables['page']['#cache']['contexts'][] = 'url.query_args:iframe_resizer';
if (silverback_iframe_inject_resizer()) {
$injectJs = TRUE;
}
}
if ($injectJs) {
$variables['#attached']['library'][] = 'silverback_iframe/iframe_resizer';
}
}
/**
* Implements hook_module_implements_alter().
*/
function silverback_iframe_module_implements_alter(&$implementations, $hook) {
if ($hook === 'page_top') {
$group = $implementations['silverback_iframe'];
unset($implementations['silverback_iframe']);
$implementations['silverback_iframe'] = $group;
}
}
/**
* Implements hook_page_top().
*/
function silverback_iframe_page_top(array &$page_top) {
if (silverback_iframe_theme_enabled()) {
unset($page_top['toolbar']);
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function silverback_iframe_form_webform_settings_confirmation_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if (\Drupal::config('silverback_iframe.settings')->get('limit_webform_confirmation_options') ?? TRUE) {
$allowed = [
WebformInterface::CONFIRMATION_URL,
WebformInterface::CONFIRMATION_URL_MESSAGE,
WebformInterface::CONFIRMATION_MESSAGE,
WebformInterface::CONFIRMATION_INLINE,
WebformInterface::CONFIRMATION_NONE,
];
$default = WebformInterface::CONFIRMATION_INLINE;
foreach (array_keys($form['confirmation_type']['confirmation_type']['#options']) as $key) {
if (!in_array($key, $allowed, TRUE)) {
unset($form['confirmation_type']['confirmation_type']['#options'][$key]);
}
}
if (!in_array($form['confirmation_type']['confirmation_type']['#default_value'], $allowed, TRUE)) {
$form['confirmation_type']['confirmation_type']['#default_value'] = $default;
}
}
}
/**
* Implements hook_entity_type_build().
*/
function silverback_iframe_entity_type_build(array &$entity_types) {
if (isset($entity_types['webform_submission'])) {
$entity_types['webform_submission']->setFormClass('add', WebformSubmissionForm::class);
}
}