Issue Bug Closed

#87087StaticRouteResolver ignores additional parameters

F Altrock 12/05/18, 16:34 updated 02/27/20, 12:41

Description

Use case: I want to have a static route sitemap.xml that shows the result of ?type=1533906435&sitemap=pages,
which is the sitemap XML for a particular site.

Adding the parameters either directly to a t3://page? URI or via the link wizard in “Additional link parameters”
results in the renderIndex method of the XmlSitemapRenderer to be invoked, instead of renderSitemap…

As it turns out, the StaticRouteResolver “sees” the additional parameter by parsing the typoLink through
@LinkService@, but they are returned opaquely as the “parameters” key, in the form sitemap=pages.
When the target URL of the static route is resolved, this value is ignored, and generateUri of the PageRouter
also cannot understand additional parameters in that way.

The relevant piece of code:
https://github.com/TYPO3-CMS/frontend/blob/d896e39da04ce86a2d179e1f5535737114130005/Classes/Middleware/StaticRouteResolver.php#L105-L113

protected function getPageUri(ServerRequestInterface $request, Site $site, array $urlParams): string
{
    $uri = $site->getRouter()->generateUri(
        (int)$urlParams['pageuid'],
        ['type' => $urlParams['pagetype'] ?? 0, '_language' => $request->getAttribute('language', null)],
        '',
        RouterInterface::ABSOLUTE_URL
    );
    return (string)$uri;
}

Using parse_str on the extracted query string and merging the result into the parameters for generateUri
fixes my particular use case:

protected function getPageUri(ServerRequestInterface $request, Site $site, array $urlParams): string
{
    parse_str($urlParams['parameters'] ?: '', $extraParams);
    $uri = $site->getRouter()->generateUri(
        (int)$urlParams['pageuid'],
        array_merge(
            ['type' => $urlParams['pagetype'] ?? 0, '_language' => $request->getAttribute('language', null)],
            $extraParams
        ),
        '',
        RouterInterface::ABSOLUTE_URL
    );
    return (string)$uri;
}

Unfortunately I have no real clue about how to make this a proper patch with Tests.

Reviews 2