public function ModalPageService::getModalToShowByPage in Modal 5.0.x
Same name and namespace in other branches
- 4.0.x src/Service/ModalPageService.php \Drupal\modal_page\Service\ModalPageService::getModalToShowByPage()
- 4.1.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::getModalToShow in src/
Service/ ModalPageService.php - Get modal to show.
File
- src/
Service/ ModalPageService.php, line 287
Class
- ModalPageService
- Modal Page Service Class.
Namespace
Drupal\modal_page\ServiceCode
public function getModalToShowByPage($modal, $currentPath) {
$pages = $modal
->getPages();
$pages = explode(PHP_EOL, $pages);
$currentPath = mb_strtolower($currentPath);
foreach ($pages as $page) {
$path = mb_strtolower($page);
if ($path != '<front>') {
$path = Xss::filter($path);
}
// $path = ltrim(trim($path), '/');.
$path = trim($path);
$currentPath = $this->aliasManager
->getPathByAlias($currentPath);
if ($currentPath == $path || $path == NULL) {
return $modal;
}
// Check wildcard.
if (strpos($path, '*') === FALSE) {
return FALSE;
}
$path = str_replace('/*', '', $path);
$path = str_replace('*', '', $path);
if (strpos($currentPath, $path) === 0) {
return $modal;
}
}
}