Skip to content

Commit

Permalink
Use page language instead of _locale parameter for $_GET['language']
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Apr 8, 2020
1 parent bd43b42 commit 21a9efe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
1 change: 0 additions & 1 deletion core-bundle/src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ services:
class: Contao\CoreBundle\Routing\Enhancer\InputEnhancer
arguments:
- '@contao.framework'
- '%contao.prepend_locale%'

contao.routing.language_filter:
class: Contao\CoreBundle\Routing\Matcher\LanguageFilter
Expand Down
16 changes: 5 additions & 11 deletions core-bundle/src/Routing/Enhancer/InputEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,19 @@ class InputEnhancer implements RouteEnhancerInterface
*/
private $framework;

/**
* @var bool
*/
private $prependLocale;

/**
* @internal Do not inherit from this class; decorate the "contao.routing.input_enhancer" service instead
*/
public function __construct(ContaoFramework $framework, bool $prependLocale)
public function __construct(ContaoFramework $framework)
{
$this->framework = $framework;
$this->prependLocale = $prependLocale;
}

public function enhance(array $defaults, Request $request): array
{
if (!isset($defaults['pageModel']) || !$defaults['pageModel'] instanceof PageModel) {
$page = $defaults['pageModel'] ?? null;

if (!$page instanceof PageModel) {
return $defaults;
}

Expand All @@ -52,9 +48,7 @@ public function enhance(array $defaults, Request $request): array
/** @var Input $input */
$input = $this->framework->getAdapter(Input::class);

if ($this->prependLocale && !empty($defaults['_locale'])) {
$input->setGet('language', $defaults['_locale']);
}
$input->setGet('language', $page->rootLanguage);

if (empty($defaults['parameters'])) {
return $defaults;
Expand Down

0 comments on commit 21a9efe

Please sign in to comment.