You are here

protected function ModalPage::getModalIds in Modal 8.3

Same name and namespace in other branches
  1. 8.2 src/ModalPage.php \Drupal\modal_page\ModalPage::getModalIds()

Get ids modal.

Parameters

string $currentPath: Current path.

string $modalParameter: Parameter for show modal.

Return value

mixed Return ids list.

1 call to ModalPage::getModalIds()
ModalPage::getModalToShow in src/ModalPage.php
Get modal to show.

File

src/ModalPage.php, line 342

Class

ModalPage
Modal Page Class.

Namespace

Drupal\modal_page

Code

protected function getModalIds(string $currentPath, string $modalParameter) {
  $query = $this->entityTypeManager
    ->getStorage('modal_page_modal')
    ->getQuery();
  if ($modalParameter) {
    $query
      ->condition('parameters', '%' . $modalParameter . '%', 'like');
  }
  else {
    $currentPath = $this->aliasManager
      ->getPathByAlias($currentPath);
    $groupCondition = $query
      ->orConditionGroup();

    // Get all itens with wildcard.
    $groupCondition
      ->condition('pages', '%*%', 'like');

    // Get all with current path.
    $groupCondition
      ->condition('pages', '%' . $currentPath . '%', 'like');

    // Get all with NULL (all pages).
    $groupCondition
      ->condition('pages', NULL, 'IS');
    $query
      ->condition($groupCondition);
  }
  if (!empty($this->languageManager
    ->getCurrentLanguage()
    ->getId())) {
    $lang_code = $this->languageManager
      ->getCurrentLanguage()
      ->getId();
    $condition = $query
      ->orConditionGroup()
      ->condition('langcode', $lang_code, '=')
      ->condition('langcode', '', '=');
    $query
      ->condition($condition);
  }
  return $query
    ->execute();
}