You are here

public function RedhenConnections::access in RedHen CRM 8

Checks access for a specific request.

Parameters

\Drupal\Core\Session\AccountInterface $account: Run access checks for this account.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

File

modules/redhen_connection/src/Controller/RedhenConnections.php, line 107

Class

RedhenConnections
Class RedhenConnections.

Namespace

Drupal\redhen_connection\Controller

Code

public function access(AccountInterface $account) {
  $own = FALSE;
  if ($entity = redhen_connection_get_connection_entity_from_route()) {
    $entity_type_key = $entity
      ->getEntityTypeId();
    if (method_exists($entity, 'getUserId')) {
      $own = $entity
        ->getUserId() == $account
        ->id();
    }
    elseif (method_exists($entity, 'getOwnerId')) {
      $own = $entity
        ->getOwnerId() == $account
        ->id();
    }
  }
  if ($own) {
    return AccessResult::allowedIf($account
      ->hasPermission('view active connection entities') || $account
      ->hasPermission('view own active ' . $entity_type_key . ' connection'));
  }
  else {
    return AccessResult::allowedIf($account
      ->hasPermission('view active connection entities'));
  }
}