You are here

public function ModalPageHelperService::verifyIfUserHasAccessOnModal in Modal 4.1.x

Same name and namespace in other branches
  1. 4.0.x src/Service/ModalPageHelperService.php \Drupal\modal_page\Service\ModalPageHelperService::verifyIfUserHasAccessOnModal()

Method to verify if User Has Access on Modal.

File

src/Service/ModalPageHelperService.php, line 51

Class

ModalPageHelperService
Modal Page Helper Service Class.

Namespace

Drupal\modal_page\Service

Code

public function verifyIfUserHasAccessOnModal($modal) {
  $modalIsPublic = $this
    ->verifyIfModalIsAvailableForEveryone($modal);

  // If Modal is Public return TRUE.
  if ($modalIsPublic) {
    return TRUE;
  }
  $user = $this->entityTypeManager
    ->getStorage('user')
    ->load($this->loggedUser
    ->id());
  $modalRoles = $modal
    ->getRoles();
  foreach ($modalRoles as $role) {
    $userHasRole = $user
      ->hasRole($role);

    // If user has role return TRUE.
    if ($userHasRole) {
      return TRUE;
    }
  }
  return FALSE;
}