Bug #87087

StaticRouteResolver ignores additional parameters

Added by F Altrock 8 days ago. Updated 6 days ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Frontend
Target version:
-
Start date:
2018-12-05
Due date:
% Done:

0%

TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

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.

History

#1 Updated by Josef Glatz 7 days ago

Just as a reference: according to the Feature Description https://docs.typo3.org/typo3cms/extensions/core/latest/Changelog/9.5/Feature-86214-ImplementStaticRoutes.html#implementation of the core: parameters are not available there – the matching is done solely on the path level.

#2 Updated by F Altrock 6 days ago

Well yes, matching on the parameters is way too complex. That's not what I'm after though:
My use case is a static route of a simple path "sitemap.xml" and I need the target URL to
have additional parameters. If the Site configuration form offers me the default typoLink
wizard for this field, then I should be able to use all fields. Sure, class, target, and
title make no sense for a route, but parameters do.

Also available in: Atom PDF