[BUGFIX] Streamline PageTypeDecorator handling 53/58553/2
authorOliver Hader <oliver@typo3.org>
Tue, 2 Oct 2018 06:47:36 +0000 (08:47 +0200)
committerBenni Mack <benni@typo3.org>
Tue, 2 Oct 2018 07:24:32 +0000 (09:24 +0200)
* uses '&type=xyz' argument value of query in case no PageType decorator
  has been configured or if no value could be resolved (not defined in
  'map' nor as 'default' value)
* allows using 'default' value without having it defined in 'map' (values
  always should be explicit, however this is a fallback handling)

Resolves: #86538
Releases: master
Change-Id: I32ddbaebba916f875f6cd76609fce6b4172eee4d
Reviewed-on: https://review.typo3.org/58553
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Richard Haeser <richard@maxserv.com>
Tested-by: Richard Haeser <richard@maxserv.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
typo3/sysext/core/Classes/Routing/Enhancer/AbstractEnhancer.php
typo3/sysext/core/Classes/Routing/Enhancer/PageTypeDecorator.php
typo3/sysext/core/Classes/Routing/PageRouter.php

index f342479..29a690f 100644 (file)
@@ -84,7 +84,7 @@ abstract class AbstractEnhancer implements EnhancerInterface
      */
     protected function resolveType(Route $route, array &$remainingQueryParameters): string
     {
-        $type = 0;
+        $type = $remainingQueryParameters['type'] ?? 0;
         $decoratedParameters = $route->getOption('_decoratedParameters');
         if (isset($decoratedParameters['type'])) {
             $type = $decoratedParameters['type'];
index 63cbc10..9a0b53f 100644 (file)
@@ -97,7 +97,7 @@ class PageTypeDecorator extends AbstractEnhancer implements DecoratingEnhancerIn
     public function decorateForMatching(RouteCollection $collection, string $routePath): void
     {
         $decoratedRoutePath = null;
-        $decoratedParameters = ['type' => 0];
+        $decoratedParameters = null;
 
         $pattern = $this->buildRegularExpressionPattern();
         if (preg_match('#(?P<decoration>(?:' . $pattern . '))#', $routePath, $matches, PREG_UNMATCHED_AS_NULL)) {
@@ -112,7 +112,13 @@ class PageTypeDecorator extends AbstractEnhancer implements DecoratingEnhancerIn
             $parameterValue = $matches['indexItems'] ?? $matches['slashedItems'] ?? $matches['regularItems'];
             $routePathValuePattern = $this->quoteForRegularExpressionPattern($routePathValue) . '$';
             $decoratedRoutePath = preg_replace('#' . $routePathValuePattern . '#', '', $routePath);
-            $decoratedParameters = ['type' => $this->map[$parameterValue] ?? 0];
+
+            $mappedType = $this->map[$parameterValue];
+            if ($mappedType !== null) {
+                $decoratedParameters = ['type' => $mappedType];
+            } elseif ($this->default === $routePathValue) {
+                $decoratedParameters = ['type' => 0];
+            }
         }
 
         foreach ($collection->all() as $route) {
@@ -122,7 +128,12 @@ class PageTypeDecorator extends AbstractEnhancer implements DecoratingEnhancerIn
                     '/' . trim($decoratedRoutePath, '/')
                 );
             }
-            $route->setOption('_decoratedParameters', $decoratedParameters);
+            if ($decoratedParameters !== null) {
+                $route->setOption(
+                    '_decoratedParameters',
+                    $decoratedParameters
+                );
+            }
         }
     }
 
@@ -185,6 +196,9 @@ class PageTypeDecorator extends AbstractEnhancer implements DecoratingEnhancerIn
     protected function buildRegularExpressionPattern(bool $useNames = true): string
     {
         $items = array_keys($this->map);
+        if ($this->default !== '' && !in_array($this->default, $items, true)) {
+            $items[] = $this->default;
+        }
         $slashedItems = array_filter($items, [$this, 'needsSlashPrefix']);
         $regularItems = array_diff($items, $slashedItems);
 
index 023b0b3..453bf8f 100644 (file)
@@ -523,7 +523,7 @@ class PageRouter implements RouterInterface
      */
     protected function resolveType(Route $route, array &$remainingQueryParameters): string
     {
-        $type = 0;
+        $type = $remainingQueryParameters['type'] ?? 0;
         $decoratedParameters = $route->getOption('_decoratedParameters');
         if (isset($decoratedParameters['type'])) {
             $type = $decoratedParameters['type'];