protected function SnippetAccess::roleCheck in Hotjar 8
Same name and namespace in other branches
- 8.2 src/SnippetAccess.php \Drupal\hotjar\SnippetAccess::roleCheck()
Check Hotjar code should be added for user.
Return value
\Drupal\Core\Access\AccessResult Result.
1 call to SnippetAccess::roleCheck()
- SnippetAccess::check in src/
SnippetAccess.php - Determines whether we add tracking code to page.
File
- src/
SnippetAccess.php, line 249
Class
- SnippetAccess
- Class SnippetAccess.
Namespace
Drupal\hotjarCode
protected function roleCheck() {
$visibility = $this->settings
->getSetting('visibility_roles');
$enabled = $visibility;
$roles = $this->settings
->getSetting('roles');
// The hotjar_roles stores the selected roles as an array where
// the keys are the role IDs. When the role is not selected the
// value is 0. If a role is selected the value is the role ID.
$checked_roles = array_filter($roles);
if (empty($checked_roles)) {
// No role is selected for tracking, therefore all roles be tracked.
return AccessResult::allowed();
}
if (count(array_intersect($this->currentUser
->getRoles(), $checked_roles))) {
$enabled = !$visibility;
}
return AccessResult::forbiddenIf(!$enabled);
}