0

I just checked that an alias path named, say, any/path can point to N different existing paths. Is there any fixed precedence order as per which one will be processed? Or is it a random order?

  • Well, right you are, still - and looks like a specific language has precedence over neutral. I just don't know if this is a random behavior or a rule-of-thumb. – Artur Nov 27 '12 at 18:20
  • From the user interface it is not possible to have two records for the same path alias, and the same language, but pointing to different internal paths. Calling path_save() it is possible. See my answer to understand which alias would be used. – kiamlaluno Nov 27 '12 at 18:58
0

Using the user interface, it is not possible to set the same alias pointing to different destinations for the same language.
If a module would execute code similar to the following one, it would be possible to have two records for the same alias.

$path = array(
  'alias' => 'homepage',
  'source' => 'node/1',
);
path_save($path);

$path = array(
  'alias' => 'homepage',
  'source' => 'node/2',
);
path_save($path);

drupal_lookup_path() contains the following code to retrieve the internal path associated with a path alias from the database. $path_language is the last argument passed to the function; when the function doesn't get that argument, it uses the value of $GLOBALS['language_url']->language.

    if ($path_language == LANGUAGE_NONE) {
      unset($args[':language']);
      $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language = :language_none ORDER BY pid DESC", $args)->fetchField();
    }
    elseif ($path_language > LANGUAGE_NONE) {
      $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language IN (:language, :language_none) ORDER BY language DESC, pid DESC", $args)->fetchField();
    }
    else {
      $alias = db_query("SELECT alias FROM {url_alias} WHERE source = :source AND language IN (:language, :language_none) ORDER BY language ASC, pid DESC", $args)->fetchField();
    }

If $path_language is equal to LANGUAGE_NONE (i.e. you are looking for the internal path associated with the language-independent alias), drupal_lookup_path('source') returns the internal path which is saved in the path_alias table with the higher pid (which normally is the latest created row).
If $path_language is not equal to LANGUAGE_NONE, the database rows are ordered to get the language-specific alias before the language-neutral, and then by pid. Also in this case, the returned internal path would be the last created one.

Suppose url_alias contains the following values.

pid   | source    | alias      | language
4     | node/1    | homepage   | und
5     | node/2    | homepage   | und
8     | node/21   | homepage   | it
9     | node/22   | homepage   | it
10    | node/31   | homepage   | xx-lolspeak
11    | node/32   | homepage   | xx-lolspeak

What I would get from that table is:

  • drupal_lookup_path('source', 'homepage'): node/2
    It returns the last created alias that is language-independent.

  • drupal_lookup_path('source', 'homepage', 'es'): node/2
    There isn't an alias for Spanish, and the function fallback to the language-independent alias. It gets the last created alias.

  • drupal_lookup_path('source', 'homepage', 'xx-lolspeak'): node/32
    It returns the last created alias for Lol Speak.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.