You are here

private function DefaultCommandSubscriber::checkRole in Googalytics - Google Analytics 8

Check role restrictions.

Parameters

string $mode: The role mode; either 'include' or 'exclude'.

array $limitRoles: An array of roles to check against.

array $userRoles: The array of roles a user belongs to.

Return value

bool TRUE if the provided restriction is passed.

1 call to DefaultCommandSubscriber::checkRole()
DefaultCommandSubscriber::onCollectDefaultCommands in src/EventSubscriber/DefaultCommandSubscriber.php
Add default events according to configuration.

File

src/EventSubscriber/DefaultCommandSubscriber.php, line 204

Class

DefaultCommandSubscriber
Class DefaultCommandSubscriber.

Namespace

Drupal\ga\EventSubscriber

Code

private function checkRole($mode, array $limitRoles, array $userRoles) {
  switch ($mode) {
    case 'disabled':
      return TRUE;
    case 'include':
      $userRoleMode = TRUE;
      break;
    case 'exclude':
      $userRoleMode = FALSE;
      break;
    default:
      throw new \InvalidArgumentException("Mode must be one of 'include' or 'exclude'");
  }
  $userRoleCommon = array_intersect($limitRoles, $userRoles);
  if ($userRoleMode ^ !empty($userRoleCommon)) {
    return FALSE;
  }
  return TRUE;
}