You are here

public function ModalPage::getModalToShowByPage in Modal 8.3

Same name and namespace in other branches
  1. 8.2 src/ModalPage.php \Drupal\modal_page\ModalPage::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 ModalPage::getModalToShowByPage()
ModalPage::getModalToShow in src/ModalPage.php
Get modal to show.

File

src/ModalPage.php, line 258

Class

ModalPage
Modal Page Class.

Namespace

Drupal\modal_page

Code

public function getModalToShowByPage($modal, $currentPath) {
  $pages = $modal->pages->value;
  $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;
    }
  }
}