2

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.

The docs (https://docs.typo3.org/typo3cms/extensions/core/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html) says:

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

And also:

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.

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

With pleasure, but how?

exotec
  • 439
  • 4
  • 17

1 Answers1

3

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:

enter image description here

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

exotec
  • 439
  • 4
  • 17
  • 2
    (TYPO3 9.5.8): Registering the _Custom Routing Aspects Mapper_ in `ext_tables.php` (as currently suggested) seems to make this aspect mapper only available for logged-in (i.e. Backend) users. Opening a route with this custom aspect as a non-logged-in user (e.g. in an incognito tab) will result in TYPO throwing an "aspect not found" exception. I resolved this problem by registering the aspect in my `AdditionalConfiguration.php`. This is conceptually identical to how the TYPO core does it: https://github.com/TYPO3/TYPO3.CMS/blob/v9.5.8/typo3/sysext/core/Configuration/DefaultConfiguration.php – Abdull Jul 17 '19 at 10:24
  • Registering of the custom aspect mapper needs to be done in `ext_localconf.php`. [Reference](https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Routing/ExtendingRouting.html#writing-custom-aspects) – chris Sep 10 '20 at 16:09
  • I am also having the issue that my links contain a "cHash" parameter. I implemented a custom "Enhancer" and now also tried to implement a custom "Mapper". But I still have the "cHash" parameters. No matter what I do, this does not work. Can I see your full code on the custom mapper somewhere? Thanks – Klaus Apr 28 '21 at 12:32
  • Hi Klaus, you can find the code here: https://gitlab.com/exotec/cardealer/-/tree/master/Classes/Routing/Aspect – exotec Apr 30 '21 at 10:14