phptypo3extbasetypo3-8.xrealurl

Typo3 8.7.x / Extbase / Realurl: Add prefix for generated html page


Is it possible to add a prefix for the generated pages of my extension by realurl? I'm using the following configuration:

...
'postVarSets' => [
    '_DEFAULT' => [


        'gallery' => [
            [
                'GETvar' => 'tx_myext_p1gallery[action]',
                'noMatch' => 'bypass',
            ],
            [
                'GETvar' => 'tx_myext_p1gallery[controller]',
                'noMatch' => 'bypass',
            ],
            [
                'GETvar' => 'tx_myext_p1gallery[backId]',
                'noMatch' => 'bypass',
            ],
            [
                'GETvar' => 'tx_myext_p1gallery[gallery]',
                'lookUpTable' => [
                    'table' => 'tx_myext_domain_model_gallery',
                    'id_field' => 'uid',
                    'alias_field' => 'title',
                    'addWhereClause' => 'AND NOT deleted',
                    'useUniqueCache' => 1,
                    'useUniqueCache_conf' => [
                        'strtolower' => 1,
                        'spaceCharacter' => '-',
                    ],
                ],
            ],
            [
                'GETvar' => 'tx_myext_p1gallery[page]',
            ],
        ],

Now I've got a url like this: https://www.mydomain/galerie/2016-foobar/1.html But I want this https://www.mydomain/galerie/2016-foobar/page1.html


Solution

  • The only solution - as I know - will be to use a userFunc which add this behavior.

            [
                'GETvar' => 'tx_myext_p1gallery[page]',
                'userFunc' => SomeClass::class . '->somefunction'
            ],
    

    Your function should then add the page prefix on encode or remove the prefix on decode.

    public function somefunction($parameters = [])
    {
      $value = $parameters['value'];
    
      if ($parameters['decodeAlias']) {
         return preg_replace('#^page([0-9]*)$#i', '$1', $value);
      } else {
         return 'page' . $value;
      }
    }