【问题标题】:How to let the query parameter "type" overwrite the PageTypeDecorator Settings?如何让查询参数“type”覆盖PageTypeDecorator设置?
【发布时间】: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);
}

这很好用!

【问题讨论】:

    标签: routes typo3 typo3-9.x


    【解决方案1】:

    您不需要 XCLASS。您可以根据需要编写自定义路由增强器:https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Routing/ExtendingRouting.html

    【讨论】:

      猜你喜欢
      • 2021-08-16
      • 1970-01-01
      • 2022-08-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多