-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcleverpush.module
44 lines (39 loc) · 1.67 KB
/
cleverpush.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
<?php
/**
* Implements hook_page_attachments().
*/
function cleverpush_page_attachments(array &$page) {
$config = \Drupal::config('cleverpush.settings');
$channelId = $config->get('channelId');
$subdomain = $config->get('subdomain');
$module_handler = \Drupal::service('module_handler');
// $module_path = $module_handler->getModule('cleverpush')->getPath();
if (!empty($channelId)) {
if (!empty($config->get('workerFile'))) {
$script_content = '
window.cleverPushConfig = {
serviceWorkerFile: \'' . $config->get('workerFile') . '\',
};';
$page['#attached']['html_head'][] = [[
'#tag' => 'script',
'#value' => $script_content,
], 'cleverpush_script'];
}
$page['#attached']['html_head'][] = [[
'#tag' => 'script',
'#attributes' => [
'async' => true,
'src' => 'https://static.cleverpush.com/channel/loader/' . $channelId . '.js'
]
], 'cleverpush_sdk_script'];
} else if (!empty($subdomain)) {
$script_content = '
(function(c,l,v,r,p,s,h){c[\'CleverPushObject\']=p;c[p]=c[p]||function(){(c[p].q=c[p].q||[]).push(arguments)},c[p].l=1*new Date();s=l.createElement(v),h=l.getElementsByTagName(v)[0];s.async=1;s.src=r;h.parentNode.insertBefore(s,h)})(window,document,\'script\',\'//' . $subdomain . '.cleverpush.com/loader.js\',\'cleverpush\');
cleverpush(\'triggerOptIn\');
';
$page['#attached']['html_head'][] = [[
'#tag' => 'script',
'#value' => $script_content,
], 'cleverpush_script'];
}
}