Commit f9c28d48 authored by Stefan Bürk's avatar Stefan Bürk Committed by Benni Mack
Browse files

[BUGFIX] Respect '_language' argument for typoLink and LinkHandler

This patch fixes a bug where a t3 page URI with _language != 0
was resolved to a page in the default language. This caused
automatically generated redirects to translated pages to
redirect to the page in the default language.

We now use the same override handling for the '_language'
parameter (as already existed for 'L') when t3 page URIs are
resolved. Also, we ensure that both parameters are always removed
when the final URL is generated. Furthermore, this patch adds
tests to cover these cases.

Using the historical 'L' parameter still works and has been
added to be handled as language override.

Background information:

The '_language parameter' is the preferred parameter to
be used to specify the language in a t3 URI, not 'L'.

The behaviour of creating auto redirects on slug changes
was changed previously: The target was added as
LinkHandler URI (instead of the path). Along with this change,
the '_language' parameter was used to ensure the
target URL is generated in the needed language (#89327).

This introduced a problem where a redirect always redirected
to the page in default language if a t3: page URI was used with
'_language'.

Resolves: #96043
Related: #89327
Releases: master, 11.5, 10.4
Change-Id: I95bdeff4827eed3be30528c02331b9c9ff2836b1
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72242


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Sybille Peters's avatarSybille Peters <sypets@gmx.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Sybille Peters's avatarSybille Peters <sypets@gmx.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 8a455d39
...@@ -163,9 +163,18 @@ class PageLinkBuilder extends AbstractTypolinkBuilder ...@@ -163,9 +163,18 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
// Disable "?id=", for pages with no site configuration, this is added later-on anyway // Disable "?id=", for pages with no site configuration, this is added later-on anyway
unset($queryParameters['id']); unset($queryParameters['id']);
// Override language property if not being set already // Override language property if not being set already, supporting historically 'L' and
if (isset($queryParameters['L']) && !isset($conf['language'])) { // modern '_language' arguments, giving '_language' the precedence.
if (isset($queryParameters['_language'])) {
if (!isset($conf['language'])) {
$conf['language'] = (int)$queryParameters['_language'];
}
unset($queryParameters['_language']);
}
if (isset($queryParameters['L'])) {
if (!isset($conf['language'])) {
$conf['language'] = (int)$queryParameters['L']; $conf['language'] = (int)$queryParameters['L'];
}
unset($queryParameters['L']); unset($queryParameters['L']);
} }
......
...@@ -23,17 +23,29 @@ entitySettings: ...@@ -23,17 +23,29 @@ entitySettings:
languageColumnNames: ['l18n_parent', 'l10n_source'] languageColumnNames: ['l18n_parent', 'l10n_source']
columnNames: {title: 'header', type: 'CType'} columnNames: {title: 'header', type: 'CType'}
defaultValues: {hidden: 0, CType: 'text'} defaultValues: {hidden: 0, CType: 'text'}
language:
tableName: 'sys_language'
columnNames: {code: 'language_isocode'}
entities: entities:
language:
- self: {id: 1, title: 'French', code: 'fr'}
- self: {id: 2, title: 'Franco-Canadian', code: 'fr'}
page: page:
- self: {id: 1000, title: 'ACME Inc', type: *pageShortcut, shortcut: 'first', root: true, slug: '/'} - self: {id: 1000, title: 'ACME Inc', type: *pageShortcut, shortcut: 'first', root: true, slug: '/'}
children: children:
- self: {id: 1100, title: 'EN: Welcome', slug: '/welcome', subtitle: 'hello-and-welcome'} - self: {id: 1100, title: 'EN: Welcome', slug: '/welcome', subtitle: 'hello-and-welcome'}
languageVariants:
- self: {id: 1101, title: 'FR: Bienvenue', language: 1, slug: '/bienvenue', subtitle: 'salut-et-bienvenue'}
- self: {id: 1102, title: 'FR-CA: Bienvenue', language: 2, slug: '/bienvenue', subtitle: 'salut-et-bienvenue'}
entities: entities:
content: content:
- self: {title: 'EN: Content Element #1'} - self: {title: 'EN: Content Element #1'}
- self: {title: 'EN: Content Element #2'} - self: {title: 'EN: Content Element #2'}
- self: {id: 1200, title: 'EN: Features', slug: '/features'} - self: {id: 1200, title: 'EN: Features', slug: '/features'}
languageVariants:
- self: {id: 1201, title: 'FR: Features', slug: '/features-fr', language: 1}
- self: {id: 1202, title: 'FR-CA: Features', slug: '/features-ca', language: 2}
- self: {id: 1300, title: 'Go to TYPO3.org', type: *pageLink, slug: '/external', url: 'typo3.org' } - self: {id: 1300, title: 'Go to TYPO3.org', type: *pageLink, slug: '/external', url: 'typo3.org' }
- self: {id: 9911, title: '<good>', slug: '/test/good'} - self: {id: 9911, title: '<good>', slug: '/test/good'}
- self: {id: 9912, title: '<good a="a/" b="thing(1)">', slug: '/test/good-a-b-spaced'} - self: {id: 9912, title: '<good a="a/" b="thing(1)">', slug: '/test/good-a-b-spaced'}
......
...@@ -200,6 +200,58 @@ class TypoLinkGeneratorTest extends AbstractTestCase ...@@ -200,6 +200,58 @@ class TypoLinkGeneratorTest extends AbstractTestCase
'user@example.org target class title &other=other', 'user@example.org target class title &other=other',
'<a href="mailto:user@example.org" title="title" target="target" class="class">user@example.org</a>', '<a href="mailto:user@example.org" title="title" target="target" class="class">user@example.org</a>',
], ],
// check link with language parameters
[
't3://page?uid=1200&L=0',
'<a href="/features">EN: Features</a>',
],
[
't3://page?uid=1200&_language=0',
'<a href="/features">EN: Features</a>',
],
[
't3://page?uid=1200&L=1',
'<a href="https://acme.fr/features-fr">FR: Features</a>',
],
[
't3://page?uid=1200&_language=1',
'<a href="https://acme.fr/features-fr">FR: Features</a>',
],
[
't3://page?uid=1201&L=1',
'<a href="https://acme.fr/features-fr">FR: Features</a>',
],
[
't3://page?uid=1201&_language=1',
'<a href="https://acme.fr/features-fr">FR: Features</a>',
],
// localized page language overrule language arguments (new and old).
// This has also test coverage through SlugGeneratorTests.
[
't3://page?uid=1202&L=1',
'<a href="https://acme.ca/features-ca">FR-CA: Features</a>',
],
[
't3://page?uid=1202&_language=1',
'<a href="https://acme.ca/features-ca">FR-CA: Features</a>',
],
// check precedence order correctness if old and modern are provided
[
't3://page?uid=1200&L=2&_language=1',
'<a href="https://acme.fr/features-fr">FR: Features</a>',
],
[
't3://page?uid=1200&_language=1&L=2',
'<a href="https://acme.fr/features-fr">FR: Features</a>',
],
[
't3://page?uid=1200&L=1&_language=2',
'<a href="https://acme.ca/features-ca">FR-CA: Features</a>',
],
[
't3://page?uid=1200&_language=2&L=1',
'<a href="https://acme.ca/features-ca">FR-CA: Features</a>',
],
]; ];
return $this->keysFromTemplate($instructions, '%1$s;'); return $this->keysFromTemplate($instructions, '%1$s;');
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment