You are here

protected function SnippetAccess::pathCheckResult in Hotjar 8

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

Check path.

Return value

\Drupal\Core\Access\AccessResult Path

1 call to SnippetAccess::pathCheckResult()
SnippetAccess::check in src/SnippetAccess.php
Determines whether we add tracking code to page.

File

src/SnippetAccess.php, line 212

Class

SnippetAccess
Class SnippetAccess.

Namespace

Drupal\hotjar

Code

protected function pathCheckResult() {
  if (!isset($this->pageMatch)) {
    $visibility = $this->settings
      ->getSetting('visibility_pages');
    $setting_pages = $this->settings
      ->getSetting('pages');
    if (!$setting_pages) {
      $this->pageMatch = TRUE;
      return AccessResult::allowed();
    }
    $pages = mb_strtolower($setting_pages);
    if ($visibility < 2) {
      $path = $this->currentPath
        ->getPath();
      $path_alias = mb_strtolower($this->aliasManager
        ->getAliasByPath($path));
      $path_match = $this->pathMatcher
        ->matchPath($path_alias, $pages);
      $alias_match = $path != $path_alias && $this->pathMatcher
        ->matchPath($path, $pages);
      $this->pageMatch = $path_match || $alias_match;

      // When $visibility has a value of 0, the tracking code is displayed on
      // all pages except those listed in $pages. When set to 1, it
      // is displayed only on those pages listed in $pages.
      $this->pageMatch = !($visibility xor $this->pageMatch);
    }
    else {
      $this->pageMatch = FALSE;
    }
  }
  return AccessResult::forbiddenIf(!$this->pageMatch);
}