You are here

public function SnippetAccess::check in Hotjar 8

Same name and namespace in other branches
  1. 8.2 src/SnippetAccess.php \Drupal\hotjar\SnippetAccess::check()

Determines whether we add tracking code to page.

Return value

bool Return TRUE if user can access snippet.

Overrides SnippetAccessInterface::check

File

src/SnippetAccess.php, line 149

Class

SnippetAccess
Class SnippetAccess.

Namespace

Drupal\hotjar

Code

public function check() {
  if (!$this->settings
    ->getSetting('account')) {
    return FALSE;
  }
  $result = AccessResult::neutral();
  $result
    ->andIf($this
    ->statusCheckResult());
  $result
    ->andIf($this
    ->pathCheckResult());
  $result
    ->andIf($this
    ->roleCheck());
  $result
    ->andIf($this
    ->cookieConstentCheck());
  $access = [];
  foreach ($this->moduleHandler
    ->getImplementations('hotjar_access') as $module) {
    $module_result = $this->moduleHandler
      ->invoke($module, 'hotjar_access');
    if (is_bool($module_result)) {
      $access[$module] = $module_result;
    }
    elseif ($module_result instanceof AccessResult) {
      $access[$module] = !$module_result
        ->isForbidden();
    }
  }
  $this->moduleHandler
    ->alter('hotjar_access', $access);
  foreach ($access as $module_result) {
    if (is_bool($module_result)) {
      $result
        ->andIf(AccessResult::forbiddenIf(!$module_result));
    }
    elseif ($module_result instanceof AccessResult) {
      $result
        ->andIf($module_result);
    }
  }
  return !$result
    ->isForbidden();
}