You are here

public function AliasStorage::preloadPathAlias in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Path/AliasStorage.php \Drupal\Core\Path\AliasStorage::preloadPathAlias()

Pre-loads path alias information for a given list of source paths.

Parameters

array $preloaded: Paths that need preloading of aliases.

string $langcode: Language code to search the path with. If there's no path defined for that language it will search paths without language.

Return value

string[] Source (keys) to alias (values) mapping.

Overrides AliasStorageInterface::preloadPathAlias

File

core/lib/Drupal/Core/Path/AliasStorage.php, line 147
Contains \Drupal\Core\Path\AliasStorage.

Class

AliasStorage
Provides a class for CRUD operations on path aliases.

Namespace

Drupal\Core\Path

Code

public function preloadPathAlias($preloaded, $langcode) {
  $langcode_list = [
    $langcode,
    LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ];
  $select = $this->connection
    ->select('url_alias')
    ->fields('url_alias', [
    'source',
    'alias',
  ]);
  if (!empty($preloaded)) {
    $conditions = new Condition('OR');
    foreach ($preloaded as $preloaded_item) {
      $conditions
        ->condition('source', $this->connection
        ->escapeLike($preloaded_item), 'LIKE');
    }
    $select
      ->condition($conditions);
  }

  // Always get the language-specific alias before the language-neutral one.
  // For example 'de' is less than 'und' so the order needs to be ASC, while
  // 'xx-lolspeak' is more than 'und' so the order needs to be DESC. We also
  // order by pid ASC so that fetchAllKeyed() returns the most recently
  // created alias for each source. Subsequent queries using fetchField() must
  // use pid DESC to have the same effect.
  if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
    array_pop($langcode_list);
  }
  elseif ($langcode < LanguageInterface::LANGCODE_NOT_SPECIFIED) {
    $select
      ->orderBy('langcode', 'ASC');
  }
  else {
    $select
      ->orderBy('langcode', 'DESC');
  }
  $select
    ->orderBy('pid', 'ASC');
  $select
    ->condition('langcode', $langcode_list, 'IN');
  return $select
    ->execute()
    ->fetchAllKeyed();
}