You are here

public function ProfileTypeMultipleAccessCheck::access in Profile 8

Performs the access check.

Parameters

\Symfony\Component\Routing\Route $route: The route to check against.

\Drupal\profile\Entity\ProfileTypeInterface $profile_type: The profile type.

Return value

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

File

src/Access/ProfileTypeMultipleAccessCheck.php, line 28

Class

ProfileTypeMultipleAccessCheck
Checks whether the profile type allows multiple profiles per user.

Namespace

Drupal\profile\Access

Code

public function access(Route $route, ProfileTypeInterface $profile_type) {
  $requirement = $route
    ->getRequirement('_profile_type_multiple');
  $requirement = filter_var($requirement, FILTER_VALIDATE_BOOLEAN);
  if ($requirement) {
    $access_result = AccessResult::allowedIf($profile_type
      ->allowsMultiple());
  }
  else {
    $access_result = AccessResult::allowedIf(!$profile_type
      ->allowsMultiple());
  }
  return $access_result
    ->addCacheableDependency($profile_type);
}