/
rollbar.module
34 lines (29 loc) · 1.12 KB
/
rollbar.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
<?php
/**
* @file
* Module file for 'rollbar'.
*/
/**
* Implements hook_page_attachments_alter().
*
* Retrieves the configured settings for the rollbar library. Attaches the
* rollbar JS snippet to the page, along with the retrieved settings as
* part of the `drupalSettings` object.
*/
function rollbar_page_attachments_alter(array &$attachments) {
$config = \Drupal::config('rollbar.settings');
// We only add the library and settings to the page if enabled.
if (!empty($config) && $config->get('enabled')) {
$settings = [
'access_token' => $config->get('access_token'),
'capture_uncaught' => $config->get('capture_uncaught'),
'capture_unhandled_rejections' => $config->get('capture_unhandled_rejections'),
'environment' => $config->get('environment'),
'rollbar_js_url' => $config->get('rollbar_js_url'),
];
// Allow alteration of the rollbar settings by other modules.
\Drupal::moduleHandler()->alter('rollbar_settings', $settings);
$attachments['#attached']['library'][] = 'rollbar/global';
$attachments['#attached']['drupalSettings']['rollbar'] = $settings;
}
}