public function ModalPageService::getModalToShowByPage in Modal 4.1.x
Same name and namespace in other branches
- 5.0.x src/Service/ModalPageService.php \Drupal\modal_page\Service\ModalPageService::getModalToShowByPage()
- 4.0.x src/Service/ModalPageService.php \Drupal\modal_page\Service\ModalPageService::getModalToShowByPage()
Get the modal by page.
Parameters
object $modal: The object modal.
string $currentPath: The current path.
Return value
object Retunr the modal.
1 call to ModalPageService::getModalToShowByPage()
- ModalPageService::loadModalsToShow in src/
Service/ ModalPageService.php - Get modal to show.
File
- src/
Service/ ModalPageService.php, line 376
Class
- ModalPageService
- Modal Page Service Class.
Namespace
Drupal\modal_page\ServiceCode
public function getModalToShowByPage($modal, $currentPath) {
$pages = $modal
->getPages();
$pages = explode(PHP_EOL, $pages);
foreach ($pages as $page) {
$path = mb_strtolower($page);
$path = trim($path);
// Check if the modal is displayed on front page.
if ($path == '<front>' && $currentPath == '<front>') {
return $modal;
}
if ($path != '<front>') {
$path = Xss::filter($path);
}
$path = trim($path);
$currentPath = $this->currentPath
->getPath();
$currentPath = $this->aliasManager
->getAliasByPath($currentPath);
if (strpos($currentPath, '/node/') !== FALSE && strpos($currentPath, '/node/') === 0) {
$currentPath = $this->aliasManager
->getAliasByPath($currentPath);
}
$currentPath = mb_strtolower($currentPath);
$shouldAppear = $this
->verifyModalShouldAppearOnThisPath($path, $currentPath);
if (!empty($shouldAppear)) {
return $modal;
}
}
}