如何为TYPO3 9 LTS编写路由方面映射器 [英] How do I write a routing aspect mapper for TYPO3 9 LTS

查看:79
本文介绍了如何为TYPO3 9 LTS编写路由方面映射器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个自定义方面映射器类,以定义可选的get参数的值.此参数包含一个带有额外数据的cf_cache标识符.但是此参数会产生一个我不需要的cHash参数,也不想在URL中看到.

I need a custom aspect mapper class, to define the value of an optional get parameter. this parameter holds an cf_cache identifier with extra data. But this parameter produces a cHash parameter what i dont need, and dont want to see in the URL's.

文档( https://docs.typo3.org/typo3cms/extensions/core/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html )说:

如果要求太宽松,则将URL签名参数("cHash")添加到无法删除的URL的末尾.

If the requirements are too loose, a URL signature parameter ("cHash") is added to the end of the URL which cannot be removed.

还有:

如果您真的需要永远不要使用cHash参数,请确保所有占位符对页面段的结果(例如分页)都有严格的定义,并可以随意构建自定义映射器.

If you really have the requirement to never have a cHash argument, ensure that all placeholders are having strict definitions on what could be the result of the page segment (e.g. pagination), and feel free to build custom mappers.

功能描述仅说明如何在ext_tables.php中注册自定义增强器类,而不说明如何使用自己的方面映射器:-(

The feature description explains only how to register a custom enhancer class in ext_tables.php, but not how to use own aspect mappers :-(

很高兴,但是如何?

推荐答案

解决方案很简单,但是文档似乎是错误的.根据文档,应该在ext_tables.php中使用$ GLOBALS ['TYPO3_CONF_VARS'] ['SYS'] ['routing'] ['CustomPlugin']注册一个Custom Enhancer.

The solution is easy, but it seems the documentation is wrong. According the docs should a Custom Enhancer registered in ext_tables.php with $GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['CustomPlugin'].

更新

如果映射器已在ext_tables.php中注册,则仅当您登录TYPO3 BE时它才有效.映射器似乎必须在ext_localconf.php中注册.然后,它可以工作而无需登录到BE

If the mapper is registered in the ext_tables.php, it only works if you are logged in to the TYPO3 BE. The mapper must seem to be registered in the ext_localconf.php. Then it works without being logged in to the BE

查看数组$ GLOBALS ['TYPO3_CONF_VARS'] ['SYS'] ['routing']显示在何处注册了Aspects和Enhancers:

A look into the array $GLOBALS['TYPO3_CONF_VARS']['SYS']['routing'] shows where Aspects and Enhancers are registered:

在ext_tables.php中注册映射器:

Register the mapper in ext_tables.php:

// Custom Routing Aspects Mapper
$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['IdentifierValueMapper'] = \VENDOR\Extension\Routing\Aspect\IdentifierValueMapper::class;

aspects类:

<?php
namespace VENDOR\Extension\Routing\Aspect;

use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;

class IdentifierValueMapper implements StaticMappableAspectInterface
{
    use SiteLanguageAwareTrait;

    /**
     * {@inheritdoc}
     */
    public function generate(string $value): ?string
    {
        ...
        return $value !== false ? (string)$value : null;
    }

    /**
     * {@inheritdoc}
     */
    public function resolve(string $value): ?string
    {
        ...
        return isset($value) ? (string)$value : null;
    }

}

在没有自定义映射器的情况下,我的URL始终具有TYPO3 cHash属性(在我的情况下,绝对无用/非常难看):

Without the custom mapper my URL's has always the (in my case absolutely useless/only ugly) TYPO3 cHash attribute:

/page/2/price/asc/03510890954e251e285104f156298e55952e4c7d?cHash = dd66994f041278f4c6bf2f7f64fb09e4

/page/2/price/asc/03510890954e251e285104f156298e55952e4c7d?cHash=dd66994f041278f4c6bf2f7f64fb09e4

现在我得到了没有cHash的URL:

Now i got URL's without the cHash:

/page/3/price/asc/ae636e66563e72d3e4f592173f328fecbee5e44f

/page/3/price/asc/ae636e66563e72d3e4f592173f328fecbee5e44f

这篇关于如何为TYPO3 9 LTS编写路由方面映射器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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