You are here

public function ModalPage::getModalToShow in Modal 8.3

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

Get modal to show.

Return value

object Return the modal to show.

1 call to ModalPage::getModalToShow()
ModalPage::checkModalToShow in src/ModalPage.php
Function to check Modal will show.

File

src/ModalPage.php, line 145

Class

ModalPage
Modal Page Class.

Namespace

Drupal\modal_page

Code

public function getModalToShow() {
  $modalToShow = FALSE;
  $currentPath = $this
    ->getCurrentPath();
  $parameters = $this->request->query
    ->all();
  $modalParameter = empty($parameters['modal']) ? FALSE : Html::escape($parameters['modal']);
  if (!empty($modalParameter)) {
    $modalParameter = $this
      ->clearText($modalParameter);
  }
  $modalIds = $this
    ->getModalIds($currentPath, $modalParameter);
  $modalStorage = $this->entityTypeManager
    ->getStorage('modal_page_modal');
  foreach ($modalIds as $modalId) {
    $modal = $modalStorage
      ->load($modalId);
    if ($modal->published->value) {
      $modalToShow = $modal->type->value === 'parameter' ? $this
        ->getModalToShowByParameter($modal, $modalParameter) : $this
        ->getModalToShowByPage($modal, $currentPath);
    }

    // Return Modal if there isn't restriction configured or if user has
    // permission.
    if (!empty($modalToShow) && (empty($modalToShow->roles->value) || $this
      ->checkUserHasPermissionOnModal($modalToShow))) {
      return $modalToShow;
    }
  }
  return FALSE;
}