Skip to content

Instantly share code, notes, and snippets.

@jacobsenj
Created June 9, 2016 09:19
Show Gist options
  • Save jacobsenj/5abbb6c80cab29e6df5aec3cccf1728e to your computer and use it in GitHub Desktop.
Save jacobsenj/5abbb6c80cab29e6df5aec3cccf1728e to your computer and use it in GitHub Desktop.
TYPO3 ext:realurl - define custom "default" language where sys_language_uid != 0 (i.e. no language param in url)

Apply default language here:

<?php
 namespace Vendor\Ext\Decoder;
 
 class UrlDecoder extends \DmitryDulepov\Realurl\Decoder\UrlDecoder {
 
     /**
      * Decodes preVars into request variables.
      *
      * @param array $pathSegments
      * @return array
      */
     protected function decodePreVars(array &$pathSegments) {
         $requestVariables = array();
 
         if (count($pathSegments) > 0) {
             $preVarsList = array_filter((array) $this->configuration->get('preVars'));
 
             $previousValue = '';
             foreach ($preVarsList as $preVarConfiguration) {
                 $this->decodeSingleVariable($preVarConfiguration, $pathSegments, $requestVariables, $previousValue);
                 if (count($pathSegments) == 0) {
                     break;
                 }
             }
 
             if (isset($requestVariables['L'])) {
                 $this->detectedLanguageId = (int) $requestVariables['L'];
             }
             elseif ($this->detectedLanguageId === 0) {
                 $defaultSysLanguageUid = (int) $this->configuration->get('init/defaultSysLanguageUid');
                 if ($defaultSysLanguageUid > 0) {
                     $this->detectedLanguageId = $defaultSysLanguageUid;
                 }
             }
         }
 
         return $requestVariables;
	
     }
 }

ext_localconf.php:

 $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['DmitryDulepov\\Realurl\\Decoder\\UrlDecoder'] = array(
	'className' => 'Vendor\\Ext\\Decoder\\UrlDecoder',
);

RealUrlConfiguration.php:

$TYPO3_CONF_VARS['EXTCONF']['realurl']['domain.de']['init']['defaultSysLanguageUid'] = 16;
$TYPO3_CONF_VARS['EXTCONF']['realurl']['domain.fr']['init']['defaultSysLanguageUid'] = 3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment