How do I write a routing aspect mapper for TYPO3 9 LTS

随声附和 提交于 2019-12-08 13:03:30

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'].

UPDATE

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

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

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;

The aspects class:

<?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;
    }

}

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

Now i got URL's without the cHash:

/page/3/price/asc/ae636e66563e72d3e4f592173f328fecbee5e44f

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!