Bug #87087
closedStaticRouteResolver ignores additional parameters
100%
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.
Updated by Josef Glatz almost 6 years 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.
Updated by F Altrock almost 6 years 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.
Updated by Tymoteusz Motylewski about 5 years ago
- Related to Bug #87817: PageLinkBuilder fails adding pagetype parameter, if routeEnhancers for PageTypeSuffix is defined added
Updated by Tymoteusz Motylewski about 5 years ago
- Related to Bug #86835: Static route sitemap.xml is still not working on single-page tree added
Updated by Tymoteusz Motylewski about 5 years ago
- Related to Bug #87817: PageLinkBuilder fails adding pagetype parameter, if routeEnhancers for PageTypeSuffix is defined added
Updated by Tymoteusz Motylewski about 5 years ago
- Related to Bug #87016: Seo sitemap does not note routeEnhancer on extensions added
Updated by Susanne Moog almost 5 years ago
- Sprint Focus set to On Location Sprint
Updated by Gerrit Code Review almost 5 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62891
Updated by Gerrit Code Review almost 5 years ago
Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62911
Updated by Benni Mack almost 5 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 58e3463297b9968c81f5c15d3e939e31226c751c.