简体   繁体   中英

Custom Routing Aspect with StaticMappableAspectInterface on TYPO3 v9 not executed

I have to make a custom routing aspect for my own TYPO3 extension which use params in URL coming from JSON (not in TYPO3 database) to remove cHash into URL for SEO purpose.

So I'm following the documentation and added a CustomValueMapper.php into myExtension/Classes/Routing/Aspect

Into this file the code below for testing purpose :

<?php
namespace VENDOR\MyExtension\Routing\Aspect;

use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

class CustomValueMapper implements StaticMappableAspectInterface
{

    /**
     * {@inheritdoc}
     */
    public function generate(string $value): ?string
    {
        DebuggerUtility::var_dump('tagadadada');
        $value = 'fr-00002032';
        return $value;
        // die($value);
        // return $value !== false ? (string)$value : null;
    }

    /**
     * {@inheritdoc}
     */
    public function resolve(string $value): ?string
    {
        DebuggerUtility::var_dump('tagadadodo');
        $value = 'fr-00002032';
        return $value;
        // die($value);
        // return isset($value) ? (string)$value : null;
    }

}

Into ext_localconf.php I added :

$GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['MyExtensionCustomValueMapper'] = \VENDOR\MyExtension\Routing\Aspect\CustomValueMapper::class;

If i debug into my Controller :

DebuggerUtility::var_dump($GLOBALS['TYPO3_CONF_VARS']['SYS']['routing'], 'mapper');

I can see my custom aspect declared into ext_localconf.php

aspects => array(7 items)
  LocaleModifier => 'TYPO3\CMS\Core\Routing\Aspect\LocaleModifier' (44 chars)
  PersistedAliasMapper => 'TYPO3\CMS\Core\Routing\Aspect\PersistedAliasMapper' (50 chars)
  PersistedPatternMapper => 'TYPO3\CMS\Core\Routing\Aspect\PersistedPatternMapper' (52 chars)
  StaticRangeMapper => 'TYPO3\CMS\Core\Routing\Aspect\StaticRangeMapper' (47 chars)
  StaticValueMapper => 'TYPO3\CMS\Core\Routing\Aspect\StaticValueMapper' (47 chars)
  MyExtensionCustomValueMapper => 'VENDOR\MyExtension\Routing\Aspect\CustomValueMapper' (47 chars)

Into the sites configuration (into config.yaml file) I added

...
routeEnhancers:
  MyCustomPlugin:
    type: Extbase
    extension: myextension
    plugin: pi1
    routes:
      - { routePath: '/', _controller: 'myController::search' }
      - { routePath: '{myParam}', _controller: 'myController::show', _arguments: {'myParam': '{myParam}'} }
    defaultController: 'myController::search'
    aspect:
      myParam:
         type: MyExtensionCustomValueMapper

So URL is rewritten with routePath and looks like

http://localhost:8080/mytestpage/fr-00002032?cHash=11a51779bcff3bc03283087ea6ff9aa1

But I don't want the cHash parameter.

In fact it's like my CustomValueMapper.php file is not read. If I add a big syntax error into it, nothings happens. No error displaying, nothing.

Into the site configuration (into config.yaml file), If you have multiple parameters sent to the controller All parameters have to be mapped, otherwise missing parameters are "hidden" in the chash parameter. for example :

routeEnhancers:
MyCustomPlugin:
type: Extbase
extension: myextension
plugin: myplugin
routes:
  - routePath: '/'
    _controller: 'myController::search'
  - routePath: '/{myParam}'
    _controller: 'myController::show'
    _arguments: 
      myParam1: 'myParam1'
      myParam2: 'myParam2'
      myParam3: 'myParam3'  
defaultController: 'myController::search'
aspect:
  myParam1:
     type: MyExtensionCustomValueMapper
  myParam2:
     type: MyExtensionCustomValueMapper
  myParam3:
     type: MyExtensionCustomValueMapper

It might be working ... Best regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM