public function ProfileAccessCheck::access in Profile 2 8
File
- src/
Access/ ProfileAccessCheck.php, line 64 - Contains \Drupal\profile\Access\ProfileAccessCheck.
Class
- ProfileAccessCheck
- Checks access to add, edit and delete profiles.
Namespace
Drupal\profile\AccessCode
public function access(AccountInterface $account, ProfileTypeInterface $profile_type = NULL) {
$access_control_handler = $this->entityManager
->getAccessControlHandler('profile');
$operation = $this->requestStack
->getCurrentRequest()->attributes
->get('operation');
if ($operation == 'add') {
return $access_control_handler
->access($profile_type, $operation, LanguageInterface::LANGCODE_DEFAULT, $account, TRUE);
}
// If checking whether a profile of a particular type may be created.
if ($profile_type) {
return $access_control_handler
->createAccess($profile_type
->id(), $account, [], TRUE);
}
// If checking whether a profile of any type may be created.
foreach ($this->entityManager
->getStorage('profile_type')
->loadMultiple() as $profile_type) {
if (($access = $access_control_handler
->createAccess($profile_type
->id(), $account, [], TRUE)) && $access
->isAllowed()) {
return $access;
}
}
// No opinion.
return AccessResult::neutral();
}