如何让查询参数“类型”覆盖PageTypeDecorator设置?

问题描述

在我的设置中,要求我可以通过查询参数覆盖页面type。从概念上讲,这里不可能进行更改。

我有一个具有以下PageType配置的TYPO3 9 LTS:

  PageTypeSuffix:
    type: PageType
    default: '.html'
    index: 'home
    map:
      '.xml': 3536236
      'sitemap.xml': 123456

以下呼叫设置正确的type=3536236

  • *。local / zh / 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);
}

这很好用!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)