HotjarSettings.php in Hotjar 8
File
src/HotjarSettings.php
View source
<?php
namespace Drupal\hotjar;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class HotjarSettings implements HotjarSettingsInterface, ContainerInjectionInterface {
const HOTJAR_PAGES = "/admin\n/admin/*\n/batch\n/node/add*\n/node/*/*\n/user/*/*";
protected $config;
protected $settings;
public function __construct(ConfigFactoryInterface $configFactory) {
$this->config = $configFactory
->get('hotjar.settings');
$this
->getSettings();
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'));
}
public function getSettings() {
if (!$this->settings) {
$settings = (array) $this->config
->getOriginal();
$settings += [
'account' => NULL,
'snippet_version' => 6,
'visibility_pages' => 0,
'pages' => static::HOTJAR_PAGES,
'visibility_roles' => 0,
'roles' => [],
];
if (empty($settings['snippet_version'])) {
$settings['snippet_version'] = 6;
}
$this->settings = $settings;
}
return $this->settings;
}
public function getSetting($key, $default = NULL) {
$this
->getSettings();
return array_key_exists($key, $this->settings) ? $this->settings[$key] : $default;
}
}