You are here

public function SocialGroupController::myGroupAccess in Open Social 8.9

Same name and namespace in other branches
  1. 8.3 modules/social_features/social_group/src/Controller/SocialGroupController.php \Drupal\social_group\Controller\SocialGroupController::myGroupAccess()
  2. 8.4 modules/social_features/social_group/src/Controller/SocialGroupController.php \Drupal\social_group\Controller\SocialGroupController::myGroupAccess()
  3. 8.5 modules/social_features/social_group/src/Controller/SocialGroupController.php \Drupal\social_group\Controller\SocialGroupController::myGroupAccess()
  4. 8.6 modules/social_features/social_group/src/Controller/SocialGroupController.php \Drupal\social_group\Controller\SocialGroupController::myGroupAccess()
  5. 8.7 modules/social_features/social_group/src/Controller/SocialGroupController.php \Drupal\social_group\Controller\SocialGroupController::myGroupAccess()
  6. 8.8 modules/social_features/social_group/src/Controller/SocialGroupController.php \Drupal\social_group\Controller\SocialGroupController::myGroupAccess()
  7. 10.3.x modules/social_features/social_group/src/Controller/SocialGroupController.php \Drupal\social_group\Controller\SocialGroupController::myGroupAccess()
  8. 10.0.x modules/social_features/social_group/src/Controller/SocialGroupController.php \Drupal\social_group\Controller\SocialGroupController::myGroupAccess()
  9. 10.1.x modules/social_features/social_group/src/Controller/SocialGroupController.php \Drupal\social_group\Controller\SocialGroupController::myGroupAccess()
  10. 10.2.x modules/social_features/social_group/src/Controller/SocialGroupController.php \Drupal\social_group\Controller\SocialGroupController::myGroupAccess()

Function that checks access on the my groups pages.

Parameters

\Drupal\Core\Session\AccountInterface $account: The account we need to check access for.

Return value

\Drupal\Core\Access\AccessResult If access is allowed.

File

modules/social_features/social_group/src/Controller/SocialGroupController.php, line 168

Class

SocialGroupController
Returns responses for Social Group routes.

Namespace

Drupal\social_group\Controller

Code

public function myGroupAccess(AccountInterface $account) {

  // Fetch user from url.
  $user = $this->requestStack
    ->getCurrentRequest()
    ->get('user');

  // If we don't have a user in the request, assume it's my own profile.
  if (is_null($user)) {

    // Usecase is the user menu, which is generated on all LU pages.
    $user = User::load($account
      ->id());
  }

  // If not a user then just return neutral.
  if (!$user instanceof User) {
    $user = User::load($user);
    if (!$user instanceof User) {
      return AccessResult::neutral();
    }
  }
  if ($user
    ->isBlocked()) {
    return AccessResult::allowedIfHasPermission($account, 'view blocked user');
  }

  // Own profile?
  if ($user
    ->id() === $account
    ->id()) {
    return AccessResult::allowedIfHasPermission($account, 'view groups on my profile');
  }
  return AccessResult::allowedIfHasPermission($account, 'view groups on other profiles');
}