问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/53053093/how-do-i-write-a-routing-aspect-mapper-for-typo3-9-lts