AliasStorage::preloadPathAlias

public AliasStorage::preloadPathAlias($preloaded, $langcode)

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 185

Class

AliasStorage
Provides a class for CRUD operations on path aliases.

Namespace

Drupal\Core\Path

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public function preloadPathAlias($preloaded, $langcode) {
  $langcode_list = [$langcode, LanguageInterface::LANGCODE_NOT_SPECIFIED];
  $select = $this->connection->select(static::TABLE)
    ->fields(static::TABLE, ['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');
  try {
    return $select->execute()->fetchAllKeyed();
  }
  catch (\Exception $e) {
    $this->catchException($e);
    return FALSE;
  }
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.