You are here

public function SocialEventInviteAccessHelper::userInviteAccess in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteAccessHelper.php \Drupal\social_event_invite\SocialEventInviteAccessHelper::userInviteAccess()
  2. 10.0.x modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteAccessHelper.php \Drupal\social_event_invite\SocialEventInviteAccessHelper::userInviteAccess()
  3. 10.1.x modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteAccessHelper.php \Drupal\social_event_invite\SocialEventInviteAccessHelper::userInviteAccess()
  4. 10.2.x modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteAccessHelper.php \Drupal\social_event_invite\SocialEventInviteAccessHelper::userInviteAccess()

Custom access check for the user invite overview.

Return value

\Drupal\Core\Access\AccessResult Returns the access result.

File

modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteAccessHelper.php, line 152

Class

SocialEventInviteAccessHelper
Class SocialEventInviteAccessHelper.

Namespace

Drupal\social_event_invite

Code

public function userInviteAccess() {
  $config = $this->configFactory
    ->get('social_event_invite.settings');
  $enabled_global = $config
    ->get('invite_enroll');

  // If it's globally disabled, we don't want to show the block.
  if (!$enabled_global) {
    return AccessResult::forbidden();
  }

  // Get the user.
  $account = $this->routeMatch
    ->getRawParameter('user');
  if (!empty($account)) {
    $account = User::load($account);
    if ($account instanceof UserInterface) {
      return AccessResult::allowedIf($account
        ->id() === $this->currentUser
        ->id());
    }
  }
  return AccessResult::neutral();
}