Add rollbar module
This commit is contained in:
parent
168fab9955
commit
51eb917570
17 changed files with 1068 additions and 1 deletions
43
web/modules/contrib/rollbar/rollbar.module
Normal file
43
web/modules/contrib/rollbar/rollbar.module
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?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'),
|
||||
];
|
||||
|
||||
// Extract host white list, if set, and add it to configuration.
|
||||
if ($hosts = $config->get('host_white_list')) {
|
||||
$host_list = explode(',', trim($hosts));
|
||||
|
||||
if (!empty($host_list)) {
|
||||
$settings['host_white_list'] = $host_list;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue