简体   繁体   English

TYPO3 9.5 Routing for custom extension (Product Navigator) - Realurl 的替换

[英]TYPO3 9.5 Routing for custom extension (Product Navigator) - replacement of Realurl

Before TYPO3 9.5 Realurl could handle URLs and I had the following realurl configuration:在 TYPO3 9.5 Realurl 可以处理 URL 之前,我有以下 realurl 配置:

'productConfiguration' => array(
        array(
                'GETvar' => 'tx_bitproducts_productview[product]',
                'lookUpTable' => array(
                        'table' => 'tx_bitproducts_domain_model_product',
                        'id_field' => 'uid',
                        'alias_field' => 'productname',
                        'addWhereClause' => '  AND (sys_language_uid=0) AND deleted=0  AND hidden=0 AND pid=185 ', 
                        'useUniqueCache' => 1,
                        'useUniqueCache_conf' => array(
                                'strtolower' => 1,
                                'spaceCharacter' => '-'
                        ),
                'enable404forInvalidAlias' => true
                )

        ),
        array(
                'GETvar' => 'tx_bitproducts_productview[action]',
                'noMatch' => 'bypass', 
                ),

        array(
                'GETvar' => 'tx_bitproducts_productview[controller]',
                'noMatch' => 'bypass'
        ),
    ),
'195' => 'productConfiguration',

In TYPO3 9.5 I need to replace this handling.在 TYPO3 9.5 中,我需要替换这种处理方式。 My Questions are:我的问题是:

  • Do I need an extra field f.eg.我是否需要一个额外的字段,例如"path_segment" in my EXTs table like in tx_news or could the URL be generated on the fly like in good old realurl ?我的 EXTs 表中的“path_segment”就像在 tx_news 中一样,或者可以像在旧的 realurl 中那样即时生成 URL 吗? This would implement, that spaces in productnames are replaced by f.eg.这将实现,产品名称中的空格被替换为 f.e. minus and the whole segment is put to lower case减号,整个段都变成小写
  • I would only like to have english product-names in the URL (pls. see above realurl config).我只想在 URL 中有英文产品名称(请参阅上面的 realurl 配置)。 Is this possible ?这可能吗 ?
  • can I do all this with RouteEnhancer type "Extbase" ?我可以用 RouteEnhancer 类型“Extbase”来做这一切吗?

I would be happy for any hints how to start this correctly我很乐意为您提供如何正确启动的任何提示

Short answer: No, you either have to add a slug field or add a custom aspect class简短回答:不,您必须添加一个 slug 字段或添加自定义方面类

Long answer:长答案:

  • There is no automatic conversion to lowercase and spaces to dashes for parameters.参数没有自动转换为小写和空格到破折号。 So either add a slug field to your table and populate it when the page title is modified or write a custom aspect class.因此,要么向表中添加一个 slug 字段并在修改页面标题时填充它,要么编写自定义方面类。
  • The PersistedAliasMapper has no way to add custom where clauses. PersistedAliasMapper 无法添加自定义 where 子句。
  • The Enhancer only maps the extbase arguments to speaking urls, eg "/some/page?plugin[controller]=MyController&plugin[action]=myAction&plugin[foo]=Some Value" => "/some/page/Some Value" with MyController and myAction set as default in in the site config. Enhancer 只将 extbase 参数映射到说话的 url,例如 "/some/page?plugin[controller]=MyController&plugin[action]=myAction&plugin[foo]=Some Value" => "/some/page/Some Value" 与 MyController 和myAction 在站点配置中设置为默认值。

So you have two possibilities: a) Add a slug field to your table and populate it with an "optimized" english value when changing the title and use the PersistedAliasMapper aspect b) Add a custom aspect class which maps the "/Some Value" segment to your optimized variant in english "/some-value" AND BACK!.因此,您有两种可能性:a) 向表中添加一个 slug 字段,并在更改标题时使用“优化的”英文值填充它,并使用 PersistedAliasMapper 方面 b) 添加映射“/Some Value”段的自定义方面类以英语“/some-value”并返回到您的优化变体!。 (In 9.5 you don't know the target language of the link [eg for language switcher], so values have to be always english, which matches your requirement :-)) (在 9.5 中,您不知道链接的目标语言 [例如语言切换器],因此值必须始终为英语,这符合您的要求 :-))

Adding an aspect class is as easy as adding one line in your ext_localconf.php:添加方面类就像在 ext_localconf.php 中添加一行一样简单:

$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['ASPECTNAME'] = MyAspect::class;

and writing a small Class implementing the StaticMappableAspectInterface with a generate and a resolve method.并编写一个使用 generate 和 resolve 方法实现 StaticMappableAspectInterface 的小类。

So if you know how to convert the "optimized" version back to the original using an aspect might be easier.因此,如果您知道如何使用方面将“优化”版本转换回原始版本可能会更容易。 If you can't revert the optimization the slug-field in the db might be easier.如果您无法恢复优化,则 db 中的 slug-field 可能会更容易。 But there is no "optimize and store original value" automatism like in realurl但是没有像 realurl 那样“优化和存储原始值”的自动化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM