You are here

public function ModalPage::checkUserHasPermissionOnModal in Modal 8.2

Same name and namespace in other branches
  1. 8.3 src/ModalPage.php \Drupal\modal_page\ModalPage::checkUserHasPermissionOnModal()

Check if the Current User has Permission to Access Modal.

1 call to ModalPage::checkUserHasPermissionOnModal()
ModalPage::getModalToShow in src/ModalPage.php
Get modal to show.

File

src/ModalPage.php, line 181

Class

ModalPage
Modal Page Class.

Namespace

Drupal\modal_page

Code

public function checkUserHasPermissionOnModal($modal) {

  /** @var \Drupal\user\Entity\User $user */
  $user = $this->entityTypeManager
    ->getStorage('user')
    ->load($this->currentUser
    ->id());
  if (empty($user) || empty($modal->roles)) {
    return FALSE;
  }
  foreach ($modal->roles as $role) {
    if (!empty($role->value) && $user
      ->hasRole($role->value)) {
      return TRUE;
    }
  }
  return FALSE;
}