Bug #87817

PageLinkBuilder fails adding pagetype parameter, if routeEnhancers for PageTypeSuffix is defined

Added by Philipp Seiler 6 months ago. Updated 4 months ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
Link Handling, Site Handling & Routing
Target version:
-
Start date:
2019-03-01
Due date:
% Done:

0%

TYPO3 Version:
9
PHP Version:
Tags:
routing,enhancer,sitemap,seo
Complexity:
Is Regression:
Sprint Focus:

Description

  • Define a RouteEnhancer for a certain page type:
    routeEnhancers:
      PageTypeSuffix:
        type: PageType
        default: ''
        map:
          foo: 1234
  • Call some method that uses TYPO3\CMS\Frontend\Typolink\PageLinkBuilder, including a typeNum as parameter.
    <f:uri.page pageType="{type}" additionalParams="{sitemap: sitemap.key, page: sitemap.page}" absolute="true" noCacheHash="false" />
    $uri = $uriBuilder->setTargetPageUid($pageUid)->setTargetPageType($pageType)->build();
  • The typeNum used in the example code above should NOT be registered in the RouteEnhancers. E.g. '5678' to fit the defined RouteEnhancer above.
  • TYPO3 then tries to use \TYPO3\CMS\Core\Routing\Enhancer\PageTypeDecorator to add the defined page type in the RouteEnhancers to the URL, although for the selected typeNum ('5678') there is no RouteEnhancer defined.
  • This leads to method decorateForGeneration() removing the typeNum:
    $deflatedParameters = $existingRoute->getOption('deflatedParameters') ?? $parameters;
    if (isset($deflatedParameters['type'])) {
        unset($deflatedParameters['type']);
        $existingRoute->setOption(
            'deflatedParameters',
            $deflatedParameters
        );
    }
  • Results in a link without typeNum added to it.

I stumbled across this, when defining a RouteEnhancer for a typeNum I used in a plugin. I also had the TYPO3 seo-extension installed, which defines the typeNum 1533906435 for getting the sitemaps. However the sitmap extension didn't create valid URLs with typeNums, and were therefore useless.

A quick fix is, to also add the typeNum defined by the seo-extension to the RouteEnhancers:

routeEnhancers:
  PageTypeSuffix:
    type: PageType
    default: ''
    map:
      foo: 1234
      sitemap: 1533906435

History

#1 Updated by Tim Karliczek 5 months ago

I am able to reproduce this behaviour in Typo3 9.5.5.

#2 Updated by Philipp Seiler 5 months ago

  • Description updated (diff)

#3 Updated by Sebastian Mazza 5 months ago

I am also able to reproduce this behaviour in Typo3 9.5.5.
(unfortunately my workaround list will be much longer)

#4 Updated by Falk no-lastname-given 4 months ago

I've spent hours to find the same issue in 9.5.6

Also available in: Atom PDF