url() with language does not return url_alias in specified language

hass - October 11, 2008 - 16:11
Project:Drupal
Version:7.x-dev
Component:base system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:by design
Description

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?

#1

catch - October 11, 2008 - 23:40
Version:6.x-dev» 7.x-dev

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

#2

Damien Tournoud - October 13, 2008 - 16:34

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:

<?php
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?

#3

Damien Tournoud - October 13, 2008 - 16:38

Oh, and you should use:

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

instead of:

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

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

#4

Damien Tournoud - October 13, 2008 - 19:48
Status:active» by design

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

#5

hass - October 13, 2008 - 20:52

THX for your help. I will try again.

 
 

Drupal is a registered trademark of Dries Buytaert.