You are here

public function OpignoModuleController::accessEntityBrowserGroups in Opigno module 3.x

Same name and namespace in other branches
  1. 8 src/Controller/OpignoModuleController.php \Drupal\opigno_module\Controller\OpignoModuleController::accessEntityBrowserGroups()

File

src/Controller/OpignoModuleController.php, line 1388

Class

OpignoModuleController
Class OpignoModuleController.

Namespace

Drupal\opigno_module\Controller

Code

public function accessEntityBrowserGroups() {
  $user = \Drupal::currentUser();

  // Load all user's groups and check is he has a group content manager role
  $is_group_content_manager = FALSE;
  foreach (\Drupal::service('group.membership_loader')
    ->loadByUser($user) as $group) {
    $member_roles = $group
      ->getGroup()
      ->getMember($user)
      ->getRoles();
    if (array_key_exists('learning_path-content_manager', $member_roles)) {
      $is_group_content_manager = TRUE;
    }
  }
  if ($is_group_content_manager || array_key_exists('administrator', $user
    ->getRoles()) || $user
    ->hasPermission('access media_entity_browser_groups entity browser pages')) {
    return AccessResult::allowed();
  }
  return AccessResult::neutral();
}