You are here

public function ModalPage::getModalByParameter in Modal 8

Function to get Modal by Parameter.

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

File

src/ModalPage.php, line 138

Class

ModalPage
Modal Page Class.

Namespace

Drupal\modal_page

Code

public function getModalByParameter($modals) {
  $modals_settings = explode(PHP_EOL, $modals);
  $parameters = $this->request->query
    ->all();
  foreach ($modals_settings as $id => $modal_settings) {
    $id = 'ModalByParameter.' . $id;
    $modal = explode('|', $modal_settings);
    $parameter_settings = Xss::filter($modal[0]);
    $parameter = trim($parameter_settings);
    $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);
    }
    $parameter_data = explode('=', $parameter);
    $parameter_key = $parameter_data[0];
    $parameter_value = $parameter_data[1];
    if (!empty($parameters[$parameter_key]) && $parameters[$parameter_key] == $parameter_value) {
      $modal = [
        'id' => $id,
        'title' => $title,
        'text' => $text,
        'button' => $button,
        'do_not_show_again' => $label_do_not_show_again,
      ];
      return $modal;
    }
  }
}