You are here

public function ModalPage::getModalByPage in Modal 8

Function to get Modal by Page.

1 call to ModalPage::getModalByPage()
ModalPage::checkModalToShow in src/ModalPage.php
Function to check Modal will show.

File

src/ModalPage.php, line 75

Class

ModalPage
Modal Page Class.

Namespace

Drupal\modal_page

Code

public function getModalByPage($modals) {
  $modals_settings = explode(PHP_EOL, $modals);
  foreach ($modals_settings as $id => $modal_settings) {
    $id = 'ModalByPage.' . $id;
    $modal = explode('|', $modal_settings);
    $path = $modal[0];
    if ($path != '<front>') {
      $path = Xss::filter($modal[0]);
    }
    $path = trim($path);
    $path = ltrim($path, '/');
    $title = Xss::filter($modal[1]);
    $title = trim($title);
    $text = Xss::filter($modal[2]);
    $text = trim($text);
    $button = Xss::filter($modal[3]);
    $button = trim($button);
    $label_do_not_show_again = FALSE;
    if (isset($modal[4]) && !empty($modal[4])) {
      $label_do_not_show_again = Xss::filter($modal[4]);
      $label_do_not_show_again = trim($label_do_not_show_again);
    }
    $is_front_page = $this->pathMatcher
      ->isFrontPage();
    if ($is_front_page) {
      $current_path = '<front>';
    }
    else {
      $current_uri = $this->request
        ->getRequestUri();
      $current_path = ltrim($current_uri, '/');
    }
    if ($path == $current_path) {
      $modal = [
        'id' => $id,
        'title' => $title,
        'text' => $text,
        'button' => $button,
        'do_not_show_again' => $label_do_not_show_again,
      ];
      return $modal;
    }
  }
}