【发布时间】:2020-08-31 08:31:27
【问题描述】:
在我的设置中,我需要通过查询参数覆盖页面type。这里的改变在概念上是不可能的。
作为基础,我有一个具有以下 PageType 配置的 TYPO3 9 LTS:
PageTypeSuffix:
type: PageType
default: '.html'
index: 'home
map:
'.xml': 3536236
'sitemap.xml': 123456
以下调用设置正确的type=3536236
- *.local/en/test?type=3536236
- *.local/en/test.xml
我需要的是以下一个:
- *.local/en/test.html?type=3536236
由于装饰器设置匹配,这实际上只设置了
type=0。
type 参数在此处必须具有更高的值。
代码中关键的地方在这里:
\TYPO3\CMS\Core\Routing\PageRouter::resolveType
这里_decoratedParameters 覆盖了一个可能设置的查询参数。
我当前的解决方案是 XClass,它改变了这种行为。
进一步考虑的是自定义 routeEnhancer 或 PageTypeDecorator。 不幸的是,我没有找到正确的地方来假设这种行为仅在解释请求时适用。
也许有人有想法?
解决方案: 目前我使用 Slack (https://typo3.slack.com/archives/C025BQLFA/p1598950920293600) 中建议的解决方案,并使用如下中间件操作请求 uri:
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface {
$uri = $request->getUri();
$uriPath = rtrim($uri->getPath(), '.html');
$uri = $uri->withPath($uriPath);
$request = $request->withUri($uri);
$GLOBALS['TYPO3_REQUEST'] = $request;
return $handler->handle($request);
}
这很好用!
【问题讨论】: