protected function ProfileAccessControlHandler::checkRoleAccess in Profile 8
Checks whether the account passes the profile type's role requirements.
If the profile type has no roles specified, the check will always pass.
Parameters
\Drupal\Core\Session\AccountInterface $account: The account.
string $profile_type_id: The profile type ID.
Return value
\Drupal\Core\Access\AccessResult The access result.
2 calls to ProfileAccessControlHandler::checkRoleAccess()
- ProfileAccessControlHandler::checkAccess in src/
ProfileAccessControlHandler.php - Performs access checks.
- ProfileAccessControlHandler::checkCreateAccess in src/
ProfileAccessControlHandler.php - Performs create access checks.
File
- src/
ProfileAccessControlHandler.php, line 63
Class
- ProfileAccessControlHandler
- Defines the access control handler for the profile entity type.
Namespace
Drupal\profileCode
protected function checkRoleAccess(AccountInterface $account, $profile_type_id) {
$profile_type = ProfileType::load($profile_type_id);
$profile_type_roles = array_filter($profile_type
->getRoles());
$role_check = !$profile_type_roles || array_intersect($account
->getRoles(), $profile_type_roles);
return AccessResult::allowedIf($role_check)
->addCacheableDependency($profile_type);
}