[BUGFIX] Streamline base variants for sites 38/59838/2
authorBenni Mack <benni@typo3.org>
Mon, 4 Mar 2019 10:57:43 +0000 (11:57 +0100)
committerBenni Mack <benni@typo3.org>
Mon, 4 Mar 2019 13:19:36 +0000 (14:19 +0100)
The base variants for site handling was implemented
without taking the site languages into account.

This changes adds the base variants to site
languages as well.

Resolves: #87831
Relates: #86303
Releases: master, 9.5
Change-Id: I2269e8cc8cf1f733cf671de4906c1be765a2b260
Reviewed-on: https://review.typo3.org/c/59838
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Nikolaj Wojtkowiak-Pfänder <nwp@dr-bock.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Nikolaj Wojtkowiak-Pfänder <nwp@dr-bock.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Classes/Site/Entity/Site.php

index e33aecd..6607b02 100644 (file)
@@ -96,15 +96,14 @@ class Site implements SiteInterface
             ]
         ];
         $baseUrl = $configuration['base'] ?? '';
-        if (isset($configuration['baseVariants']) && is_array($configuration['baseVariants'])) {
+        if (is_array($configuration['baseVariants'] ?? false)) {
             $expressionLanguageResolver = GeneralUtility::makeInstance(
                 Resolver::class,
                 'site',
                 []
             );
             foreach ($configuration['baseVariants'] as $baseVariant) {
-                $result = $expressionLanguageResolver->evaluate($baseVariant['condition']);
-                if ($result) {
+                if ($expressionLanguageResolver->evaluate($baseVariant['condition'])) {
                     $baseUrl = $baseVariant['base'];
                     break;
                 }
@@ -116,7 +115,21 @@ class Site implements SiteInterface
             $languageUid = (int)$languageConfiguration['languageId'];
             // site language has defined its own base, this is the case most of the time.
             if (!empty($languageConfiguration['base'])) {
-                $base = new Uri($this->sanitizeBaseUrl($languageConfiguration['base']));
+                $base = $languageConfiguration['base'];
+                if (is_array($languageConfiguration['baseVariants'] ?? false)) {
+                    $expressionLanguageResolver = $expressionLanguageResolver ?? GeneralUtility::makeInstance(
+                        Resolver::class,
+                        'site',
+                        []
+                    );
+                    foreach ($languageConfiguration['baseVariants'] as $baseVariant) {
+                        if ($expressionLanguageResolver->evaluate($baseVariant['condition'])) {
+                            $base = $baseVariant['base'];
+                            break;
+                        }
+                    }
+                }
+                $base = new Uri($this->sanitizeBaseUrl($base));
                 // no host given by the language-specific base, so lets prefix the main site base
                 if ($base->getScheme() === null && $base->getHost() === '') {
                     $base = rtrim((string)$this->base, '/') . '/' . ltrim((string)$base, '/');