routestypo3extbaserealurl

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:

   
'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. My Questions are:

I would be happy for any hints how to start this correctly


Solution

  • Short answer: No, you either have to add a slug field or add a custom aspect class

    Long answer:

    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!. (In 9.5 you don't know the target language of the link [e.g. for language switcher], so values have to be always english, which matches your requirement :-))

    Adding an aspect class is as easy as adding one line in your 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.

    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. But there is no "optimize and store original value" automatism like in realurl