public function ModalPageService::getModalToShow in Modal 5.0.x
Get modal to show.
Return value
object Return the modal to show.
1 call to ModalPageService::getModalToShow()
- ModalPageService::checkModalToShow in src/
Service/ ModalPageService.php - Function to check Modal will show.
File
- src/
Service/ ModalPageService.php, line 159
Class
- ModalPageService
- Modal Page Service Class.
Namespace
Drupal\modal_page\ServiceCode
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);
}
// We need to use Depency Injection on this. @codingStandardsIgnoreLine.
$modals = \Drupal::entityTypeManager()
->getStorage('modal')
->loadMultiple();
foreach ($modals as $modal) {
if (empty($modal
->getPublished())) {
continue;
}
if (empty($modal
->getType())) {
continue;
}
$modalType = $modal
->getType();
switch ($modalType) {
case 'page':
$modalToShow = $this
->getModalToShowByPage($modal, $currentPath);
break;
case 'parameter':
$modalToShow = $this
->getModalToShowByParameter($modal, $modalParameter);
break;
}
// Return Modal if there isn't restriction configured or if user has
// permission.
if (!empty($modalToShow) && $this
->checkUserHasPermissionOnModal($modalToShow)) {
return $modalToShow;
}
}
return FALSE;
}