You are here

function simple_access_groups_from_roles in Simple Access 8.3

Same name and namespace in other branches
  1. 5.2 simple_access.module \simple_access_groups_from_roles()
  2. 5 simple_access.module \simple_access_groups_from_roles()
  3. 6.2 simple_access.module \simple_access_groups_from_roles()
  4. 7.2 simple_access.module \simple_access_groups_from_roles()

Get a list of group/grant ids based on a list of user roles.

$roles string A linear list a role ids.

2 calls to simple_access_groups_from_roles()
SimpleAccessViewsAccess::access in src/views/access/SimpleAccessViewsAccess.php
Determine if the current user has access or not.
simple_access_groups_check_user in ./simple_access.module
Check if a user's role is in a group.

File

./simple_access.module, line 447
Builds simple access definition for content access.

Code

function simple_access_groups_from_roles($roles) {

  // There probably should be some 'static' stuff going on here
  // always return gid 0 just to be safe.
  $gids = [];
  $result = \Drupal::database()
    ->select('simple_access_roles', 'r')
    ->fields('r', [
    'gid',
  ])
    ->condition('rid', $roles, 'IN')
    ->execute();
  $gids = $result
    ->fetchAllAssoc('gid', PDO::FETCH_ASSOC);
  return $gids;
}