Skip to content

Commit

Permalink
Drop Deprecated Changelanguage V2 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
amenk committed Apr 4, 2020
1 parent ed9cee2 commit b7aef12
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 58 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"php": ">=5.3",
"contao/core-bundle": "~3.5 || ~4.1",
"metamodels/core": "^2.0",
"terminal42/contao-changelanguage": "*",
"terminal42/contao-changelanguage": ">=2.0",
"contao-community-alliance/composer-plugin": "^2.4 || ^3.0"
},
"extra": {
Expand Down
56 changes: 0 additions & 56 deletions contao/classes/ImiMMChangeLanguageObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,60 +174,4 @@ public function translateMMUrlsV3(
// fallback - if we do not have any translated values: use untranslated alias
$event->getUrlParameterBag()->setUrlAttribute('items', $alias);
}

/**
* Hook callback for changelanguage extension to support language switching on product reader page
* Changelanguage v2
* @deprecated
*/
public function translateMMUrlsV2($arrParams, $strLanguage, $arrRootPage, &$addToNavigation)
{
// Remove index.php fragment from uri and drop query parameters as we are not interested in those.
list($fullUri) = explode('?', str_replace('index.php/', '', \Environment::get('request')), 2);
// Handle remaining arguments, and do that only if there are exactly two.
$uri = explode('/', $fullUri);

// Remove language code
if (\Config::get('addLanguageToUrl')) {
array_shift($uri);
}

$alias = \Input::get('auto_item');
if ($alias == null) {
return $arrParams;
}

$currentMetaModels = $this->getCurrentMetamodels();

// allow overwriting of the auto-detected definition
if (isset($GLOBALS['TL_CONFIG']['mm_changelanguage'])) {
$currentMetaModels = array_merge($currentMetaModels, $GLOBALS['TL_CONFIG']['mm_changelanguage']);
}
foreach($currentMetaModels as $modelName=>$attributeName) {
$metaModel = \MetaModels\Factory::byTableName($modelName);
$attribute = $metaModel->getAttribute($attributeName); // your attribute name here.
// Only for safety here - You most definitely know that your alias is translated. ;)
if (!in_array('MetaModels\Attribute\ITranslated', class_implements($attribute))) {
continue;
}
$ids = $attribute->searchForInLanguages($alias, array($GLOBALS['TL_LANGUAGE']));
if (count($ids) < 1) {
continue;;
}
$attributeData = array_shift($attribute->getTranslatedDataFor($ids, $strLanguage));

if (is_null($attributeData)) {
// this requires https://github.com/terminal42/contao-changelanguage/pull/48
$addToNavigation = false;
} else {
$value = $attributeData['value'];
// Override URL parameter now.
$GLOBALS['TL_CONFIG']['useAutoItem'] = $uri[0];
$arrParams['url'] = array($value);
}
return $arrParams;
}

return $arrParams;
}
}
1 change: 0 additions & 1 deletion contao/config/config.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<?php
$GLOBALS['TL_HOOKS']['translateUrlParameters'][] = array('iMi\MMChangeLanguage\ImiMMChangeLanguageObserver', 'translateMMUrlsV2');
$GLOBALS['TL_HOOKS']['changelanguageNavigation'][] = array('iMi\MMChangeLanguage\ImiMMChangeLanguageObserver', 'translateMMUrlsV3');

0 comments on commit b7aef12

Please sign in to comment.