public function ModalPageService::loadModalsToShow in Modal 4.1.x
Same name and namespace in other branches
- 4.0.x src/Service/ModalPageService.php \Drupal\modal_page\Service\ModalPageService::loadModalsToShow()
Get modal to show.
Return value
object Return the modal to show.
1 call to ModalPageService::loadModalsToShow()
- ModalPageService::getModalsToShow in src/
Service/ ModalPageService.php - Method to Get Modals to show.
File
- src/
Service/ ModalPageService.php, line 215
Class
- ModalPageService
- Modal Page Service Class.
Namespace
Drupal\modal_page\ServiceCode
public function loadModalsToShow() {
$modalToShow = FALSE;
$modalsToShow = [];
$currentPath = $this
->getCurrentPath();
$parameters = $this->request->query
->all();
$modalParameter = empty($parameters['modal']) ? FALSE : Html::escape($parameters['modal']);
if (!empty($modalParameter)) {
$modalParameter = $this
->clearText($modalParameter);
}
$modals = $this->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
->verifyUserHasPermissionOnModal($modalToShow)) {
if (empty($this
->verifyModalShouldAppearOnThisLanguage($modalToShow))) {
continue;
}
// Get Modal ID.
$modalId = $modalToShow
->id();
// Enable alter for other projects with HOOK_modal_alter().
$this->projectHandler
->alter('modal', $modalToShow, $modalId);
// Get Hook Name.
$hookModalFormIdAlterName = 'modal_' . $modalId;
// Enable alter for other projects with HOOK_modal_ID_alter().
$this->projectHandler
->alter($hookModalFormIdAlterName, $modalToShow, $modalId);
$modalsToShow[] = $modalToShow;
}
}
return $modalsToShow;
}