You are here

class HotjarSettings in Hotjar 8

Same name and namespace in other branches
  1. 8.2 src/HotjarSettings.php \Drupal\hotjar\HotjarSettings

Class HotjarSettings.

@package Drupal\hotjar

Hierarchy

Expanded class hierarchy of HotjarSettings

1 string reference to 'HotjarSettings'
hotjar.services.yml in ./hotjar.services.yml
hotjar.services.yml
1 service uses HotjarSettings
hotjar.settings in ./hotjar.services.yml
Drupal\hotjar\HotjarSettings

File

src/HotjarSettings.php, line 14

Namespace

Drupal\hotjar
View source
class HotjarSettings implements HotjarSettingsInterface, ContainerInjectionInterface {
  const HOTJAR_PAGES = "/admin\n/admin/*\n/batch\n/node/add*\n/node/*/*\n/user/*/*";

  /**
   * Hotjar config.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;

  /**
   * Settings.
   *
   * @var array
   */
  protected $settings;

  /**
   * HotjarSettings constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   Config factory.
   */
  public function __construct(ConfigFactoryInterface $configFactory) {
    $this->config = $configFactory
      ->get('hotjar.settings');
    $this
      ->getSettings();
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'));
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public function getSetting($key, $default = NULL) {
    $this
      ->getSettings();
    return array_key_exists($key, $this->settings) ? $this->settings[$key] : $default;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HotjarSettings::$config protected property Hotjar config.
HotjarSettings::$settings protected property Settings.
HotjarSettings::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
HotjarSettings::getSetting public function Get setting. Overrides HotjarSettingsInterface::getSetting
HotjarSettings::getSettings public function Get all settings. Overrides HotjarSettingsInterface::getSettings
HotjarSettings::HOTJAR_PAGES constant
HotjarSettings::__construct public function HotjarSettings constructor.