public function ModalPageService::verifyUserHasPermissionOnModal in Modal 4.1.x
Same name and namespace in other branches
- 4.0.x src/Service/ModalPageService.php \Drupal\modal_page\Service\ModalPageService::verifyUserHasPermissionOnModal()
Verify if the Current User has Permission to Access Modal.
1 call to ModalPageService::verifyUserHasPermissionOnModal()
- ModalPageService::loadModalsToShow in src/
Service/ ModalPageService.php - Get modal to show.
File
- src/
Service/ ModalPageService.php, line 282
Class
- ModalPageService
- Modal Page Service Class.
Namespace
Drupal\modal_page\ServiceCode
public function verifyUserHasPermissionOnModal($modal) {
if (empty(array_filter($modal
->getRoles()))) {
return TRUE;
}
/** @var \Drupal\user\Entity\User $user */
$user = $this->entityTypeManager
->getStorage('user')
->load($this->currentUser
->id());
if (empty($user) || empty($modal
->getRoles())) {
return FALSE;
}
$roles = $modal
->getRoles();
foreach ($roles as $roleId => $role) {
// If value is = 0, we can skip.
if (empty($role)) {
return FALSE;
}
if (!empty($roleId) && $user
->hasRole($roleId)) {
return TRUE;
}
}
return FALSE;
}