We tried to get the aliased URL with url('node/'. $source_node->nid, array('language' => $source_node->language)), but we only get the internal URL with base_path.

I verified that the URL for node/11 have an alias named "impressum" and the node is shown on the site with "de/impressum". If I switch to the English version of the node/64 I get "en/imprint". Therefore from DB side it looks all correct only the url() behaves wrong and does not return the correct URL. I expected to get on the English node when I call URL with DE language the alias to the German node!?

This seems to be a bug to me. Could someone please help?

Comments

catch’s picture

Version: 6.x-dev » 7.x-dev

I doubt this code has changed in Drupal 7, so moving it there for additional eyes.

damien tournoud’s picture

Let's say you have two nodes:

- node/11 is a German node, with a path alias pointing to "de/impressum"
- node/64 is an English node (translation of node/11), with a path alias pointing to "en/imprint"

In that case, if $languages = language_list(), here is what you should see:

 url('node/11', array('language' => $languages['de'])) => 'de/impressum'
 url('node/11', array('language' => $languages['en'])) => 'node/11'
 url('node/64', array('language' => $languages['de'])) => 'node/64'
 url('node/64', array('language' => $languages['en'])) => 'en/imprint'

This is because path aliases are *per language*, and that aliases generated by nodes are in the language of their node by default.

Are you seeing anything different?

damien tournoud’s picture

Oh, and you should use:

  $languages = language_list();
  url('node/'. $source_node->nid, array('language' => $languages[source_node->language]));

instead of:

  url('node/'. $source_node->nid, array('language' => $source_node->language));

Because url() expects a language object, not a language code here.

damien tournoud’s picture

Status: Active » Closed (works as designed)

Closing this, 'language' should be a language object, not a language code, period.

hass’s picture

THX for your help. I will try again.