TYPO3 9.5:在语言/路由增强器之后放置自定义路径段 [英] TYPO3 9.5: put a custom-path segment after language / route enhancers

查看:90
本文介绍了TYPO3 9.5:在语言/路由增强器之后放置自定义路径段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 von TYPO3 8.7 迁移到 9.5 我需要替换旧的 realurl-configuration 以匹配新路由:

Migrating von TYPO3 8.7 to 9.5 I need to replace an old realurl-configuration to match the new routing:

Old-Realurl 配置:语言后国家/地区的自定义细分:

Old-Realurl Config: Custom Segment for Country after language:

'preVars' => array(
        array(
            'GETvar' => 'L',
            'valueMap' => array(
                'en' => '0', // darf nicht auskommentiert sein!
                'de' => '1',
                'pl' => '2',
                ...

        array(
            'GETvar' => 'C',
            'valueMap' => array(
                'de'=>'1',
                'ch'=>'2',
                'ch'=>'3',      

我在 TYPO3 9.5 站点配置中尝试了简单"路由增强器:

I tried "simple" route enhancer inTYPO3 9.5 Site Config:

languages:
  -
    title: English
    enabled: true
    languageId: 0
    base: /en/
    typo3Language: default
    locale: en_US.UTF-8
    iso-639-1: en
    navigationTitle: English
    hreflang: en-us
    direction: ltr
    flag: us
  -
    title: German
    enabled: true
    base: /de/
    typo3Language: de
    locale: de_DE.UTF-8
    iso-639-1: de
    navigationTitle: ''
    hreflang: ''
    direction: ''
    fallbackType: fallback
    fallbacks: ''
    flag: de
    languageId: '1'
rootPageId: 1
routes: {  }
routeEnhancers:
  Country:
    type: Simple
    routePath: '/{Country}'
    defaults:
    requirements:
      C: '[1-21]'
    aspects:
      Country:
        type: StaticValueMapper
        map:             
          de: 1
          ch: 2

但是国家段不会出现在语言和主段之间:旧网址:www.mydomain.com/de/ch/home/

But the country segments wont appear between Language and main-slug: OLD URLS: www.mydomain.com/de/ch/home/

使用我的路由增强器配置(上图):www.mydomain.com/de/home/ch/

With my rout-enhancer config (above): www.mydomain.com/de/home/ch/

有谁知道我如何实现这个自定义细分并让它出现在正确的位置?

Does anyone know how I can achive this custom segment and let it appear at the right place ?

非常感谢您的任何提示

推荐答案

路由增强器在页面 URL 之后添加了一些内容.但是,我们遇到了类似的情况.这是我必须做的才能使其正常工作:

A route enhancer adds something after the Page URL. However, we had a similar scenario. Here is what I had to do in order to make it work:

构建自定义中间件(语言解析后,在PSR-15中间件中的PSR-7请求中有一个SiteRouteResult可用)这个中间件然后获取 SiteRouteResult 的尾部",并根据给定的静态列表(就像它在列表中可用)解析参数.之后,我创建了一个新的 SiteRouteResult 对象,并从尾部删除了该 pathSegment.请记住,将解析的参数存储为页面的变体"可能非常有用,因此,可以有效地连接到 TSFE,其中 createHashBase() 构建为也在此变量中进行计算.

Build a custom middleware (after the language is resolved, and a SiteRouteResult is available in the PSR-7 Request in a PSR-15 middleware) This middleware then takes the "tail" of the SiteRouteResult, and resolves the argument based on a given static list (like it was available in the list). After that, I created a new SiteRouteResult object with that pathSegment removed from the tail. Keep in mind that it might be very useful to store the resolved argument as a "variant" of the page, thus, effectively hooking into TSFE where the createHashBase() is built to also calculate in this variable.

我建议将此字符串作为自定义属性或自定义 TSFE 属性存储在请求中.

I recommend storing this string in the request as custom property, or as a custom TSFE property.

无法使用 RouteEnhancer 解析prePathVar",因为只有在找到页面后才会选择正确的路由增强器.如果您的 URL 包含/ch/home",则 TYPO3 PageRouter 找不到正确的页面.

It is NOT possible to resolve a "prePathVar" with a RouteEnhancer, as the right route enhancers are only selected AFTER the page was found. If your URL has "/ch/home" TYPO3 PageRouter can NOT find the correct page.

创建一个充当装饰器的 RouteEnhancer(请参阅 PageType 增强器).但是,装饰器不需要取消装饰"/解析"一个 URL(什么都不做).如果您还使用 PageTypeDecorator,这会变得很棘手,因为您只能拥有一个,因此如果您还需要映射 typeNums,则可能需要从 Core 扩展一个.

Create a RouteEnhancer that acts like a decorator (see PageType enhancer). However, the decorator does not need does not "undecorate" / "resolve" an URL (do nothing). This gets tricky if you also use the PageTypeDecorator, as you can only have one, so you might need to extend the one from Core, if you also need to map typeNums.

在任何情况下,自定义增强器都可以在生成的路由前加上静态地图,具体取决于是否给定了类型.

In any case, the custom Enhancer can then prefix the generated route with the static map depending if the type is given.

希望有帮助!

这篇关于TYPO3 9.5:在语言/路由增强器之后放置自定义路径段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆