0
votes

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:

  • Do I need an extra field f.eg. "path_segment" in my EXTs table like in tx_news or could the URL be generated on the fly like in good old realurl ? This would implement, that spaces in productnames are replaced by f.eg. minus and the whole segment is put to lower case
  • I would only like to have english product-names in the URL (pls. see above realurl config). Is this possible ?
  • can I do all this with RouteEnhancer type "Extbase" ?

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

1

1 Answers

1
votes

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

Long answer:

  • There is no automatic conversion to lowercase and spaces to dashes for parameters. So either add a slug field to your table and populate it when the page title is modified or write a custom aspect class.
  • The PersistedAliasMapper has no way to add custom where clauses.
  • The Enhancer only maps the extbase arguments to speaking urls, e.g. "/some/page?plugin[controller]=MyController&plugin[action]=myAction&plugin[foo]=Some Value" => "/some/page/Some Value" with MyController and myAction set as default in in the site config.

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