[TYPO3-english] Do not understand RealURL translation [SOLVED]
Xavier Perseguers
typo3 at perseguers.ch
Sun Feb 15 09:58:16 CET 2009
Let's go a bit further, I think it may be useful for others too...
> Trying to speaking aloud...
>
>> My RealURL conf reads:
>>
>> array(
>> 'GETvar' => 'L',
>> 'valueMap' => array(
>> 'de' => '1',
>> 'fr' => '2',
>> 'it' => '3',
>> 'en' => '4',
>> ),
>> 'valueDefault' => 'fr',
>> ),
>
> Indeed (and that's the way it should work btw), the mapping of 'fr' is
> taken when generating links, leading to use '2' instead of default '0'.
> This means that I should dynamically remove the fr mapping when French
> is my default language.
valueDefault in my configuration is not arbitrarily set to "fr" but it
reads '{DYNAMIC}' to show that it will be change during page generation.
As my website as different default languages, I cannot set it to one of
them in my configuration. As such I added a TS option in config to
define the current default language:
config.defaultLanguage = fr
and then I XCLASSed realurl:
class ux_tx_realurl extends tx_realurl {
function encodeSpURL(&$params, &$ref) {
// Set the default language to be used for sys_language_uid = 0
$defaultLanguage =
$GLOBALS['TSFE']->tmpl->setup['config.']['defaultLanguage'];
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']['preVars'][1]['valueDefault']
= $defaultLanguage;
// Encode the URL
parent::encodeSpURL($params, $ref);
}
}
With this in place, when generating a "French" URL with default language
set to 'fr', I get the '/fr/' prefix for my URL.
The problem I had is that when decoding back the URL, decodeSpURL()
should be extended too to actually unset the map 'fr' => '2' which will
lead to setting the L parameter to 0 and not to 2. To do this I added
code below to my XCLASS class:
function decodeSpURL($params, &$ref) {
unset($params['pObj']->TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT']['preVars'][1]['valueMap']['fr']);
parent::decodeSpURL($params, $ref);
}
The point is that I cannot access the config defaultLanguage at this
point, it is not available (or I did not find it).
Hence, I *cannot* unset the default language mapping dynamically and as
such I have to find another way. The other way is easy: do not prepend
'/fr/' to my URL when default language is French. This means that I
should not set 'valueDefault' to any value but should use 'noMatch' =>
'bypass' instead. My final config now reads:
array(
'GETvar' => 'L',
'valueMap' => array(
'de' => '1',
'fr' => '2',
'it' => '3',
'en' => '4',
),
'noMatch' => 'bypass'
),
and there's no need to XCLASS realurl anymore.
--
Xavier Perseguers
http://xavier.perseguers.ch/en
One contribution a day keeps the fork away
More information about the TYPO3-english
mailing list