eZ Community » Forums » Developer » How to get the URL of an object in...
expandshrink

How to get the URL of an object in chosen language version

How to get the URL of an object in chosen language version

Tuesday 03 November 2009 1:28:20 pm - 4 replies

http://ez.no/fr/developer/forum/d...an_object_in_chosen_language_version

As in Piotrek Karaƛ code example, both $node->urlAlias() returns same URL, but $node->name() returns localised node titles.

<?php
$node = eZContentObjectTreeNode::fetch( 67, 'pol-PL' ); //default lang
var_dump( $node->urlAlias() );
$node = eZContentObjectTreeNode::fetch( 67, 'eng-US' );
var_dump( $node->urlAlias() );
?>

Modified on Tuesday 03 November 2009 1:29:29 pm by Jean-Luc Nguyen

Saturday 07 November 2009 3:59:11 pm

Hi Jean-Luc

Apparently the urlAlias() method does not take into account the language you fetched the node in. It completely relies on eZURLAliasML, which on its turn relies on eZContentLanguage and the prioritized language list as defined for your site access.

Although I did not try this, I think you can modify the prioritized language list, get the URL alias you want, and then restore the prioritized language list to its original value. Some code that might get you started:

$node = eZContentObjectTreeNode::fetch( 67, 'eng-US' );
 
$originalPrioritizedLanguages = eZContentLanguage::prioritizedLanguageCodes();
eZContentLanguage::setPrioritizedLanguages( array( 'eng-US' ) );
var_dump( $node->urlAlias() );
eZContentLanguage::setPrioritizedLanguages( $originalPrioritizedLanguages );

Let us know if that worked happy.gif Emoticon

Modified on Saturday 07 November 2009 4:05:53 pm by Kristof Coomans

Thursday 12 November 2009 12:50:26 pm

Thanks Kristof,

I'll check that and tell you if it works.

Monday 28 December 2009 3:19:03 pm

What I want to do is have the same URLs in all the different languages, basically turn off multilanguage URL aliases, or (to put it another way) force all siteaccesses to show the URL aliases for the main language. Do I have to write a custom method like the above or is there an easier way, like a setting somewhere, that will do this? Thanks!

Wednesday 19 May 2010 2:35:31 pm

Hi Jean-Luc

Apparently the urlAlias() method does not take into account the language you fetched the node in. It completely relies on eZURLAliasML, which on its turn relies on eZContentLanguage and the prioritized language list as defined for your site access.

Although I did not try this, I think you can modify the prioritized language list, get the URL alias you want, and then restore the prioritized language list to its original value. Some code that might get you started:

$node = eZContentObjectTreeNode::fetch( 67, 'eng-US' );
 
$originalPrioritizedLanguages = eZContentLanguage::prioritizedLanguageCodes();
eZContentLanguage::setPrioritizedLanguages( array( 'eng-US' ) );
var_dump( $node->urlAlias() );
eZContentLanguage::setPrioritizedLanguages( $originalPrioritizedLanguages );

Let us know if that worked happy.gif Emoticon

hi Kristof, I have needed that and I can say now it works well. thanks

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from