You are here

protected function PathProcessorSearchApiPage::getSearchApiPagePathsUsingCleanUrls in Search API Pages 8

Get Search API page path for clean urls.

1 call to PathProcessorSearchApiPage::getSearchApiPagePathsUsingCleanUrls()
PathProcessorSearchApiPage::processInbound in src/PathProcessor/PathProcessorSearchApiPage.php
Processes the inbound path.

File

src/PathProcessor/PathProcessorSearchApiPage.php, line 66

Class

PathProcessorSearchApiPage
Class PathProcessorSearchApiPage.

Namespace

Drupal\search_api_page\PathProcessor

Code

protected function getSearchApiPagePathsUsingCleanUrls() {
  $paths = [];
  $is_multilingual = $this->languageManager
    ->isMultilingual();
  $all_languages = $this->languageManager
    ->getLanguages();

  /* @var $search_api_page \Drupal\search_api_page\SearchApiPageInterface */
  foreach ($this->entityTypeManager
    ->getStorage('search_api_page')
    ->loadMultiple() as $search_api_page) {

    // Default path.
    $default_path = $search_api_page
      ->getPath();

    // Loop over all languages so we can get the translated path (if any).
    foreach ($all_languages as $language) {
      $path = '';

      // Check if we are multilingual or not.
      if ($is_multilingual) {
        $path = $this->languageManager
          ->getLanguageConfigOverride($language
          ->getId(), 'search_api_page.search_api_page.' . $search_api_page
          ->id())
          ->get('path');
      }
      if (empty($path)) {
        $path = $default_path;
      }

      // Use clean urls or not.
      if ($search_api_page
        ->getCleanUrl()) {
        $path .= '/';
        $paths[] = '/' . $path;
      }
    }
  }
  return $paths;
}