1.20.x path.inc path_load($conditions)

Fetches a specific URL alias from the database.

Parameters

$conditions: A string representing the source, a number representing the pid, or an array of query conditions.

Return value

FALSE if no alias was found or an associative array containing the: following keys:

  • source: The internal system path.
  • alias: The URL alias.
  • pid: Unique path alias identifier.
  • langcode: The language code of the alias.
  • auto: Boolean indicating if this alias was created from a pattern.

File

includes/path.inc, line 361
Functions to handle paths in Backdrop, including path aliasing.

Code

function path_load($conditions) {
  if (is_numeric($conditions)) {
    $conditions = array('pid' => $conditions);
  }
  elseif (is_string($conditions)) {
    $conditions = array('source' => $conditions);
  }
  elseif (!is_array($conditions)) {
    return FALSE;
  }
  $select = db_select('url_alias');
  foreach ($conditions as $field => $value) {
    $select->condition($field, $value);
  }
  $path = $select
  ->fields('url_alias')
    ->orderBy('pid', 'DESC')
    ->execute()
    ->fetchAssoc();
  // Cast the auto column to boolean or NULL if unknown.
  if ($path) {
    $path['auto'] = is_null($path['auto']) ? NULL : (bool) $path['auto'];
  }
  return $path;
}