Search code examples
typo3typo3-9.x

RouteEnhancer for custom TYPO3 extension: 404 on detail page


I have a custom extbase extension that queries read-only data from a ReST service to show it in a list and detail view. There is no data in a TYPO3 table. The URLs were processed by realURL, and this worked fine up until TYPO3 8.

Now that I'm in the process of updating to TYPO3 9.5.21 I can't get the routeEnhancer configuration for this extension to work. I managed to get the exact same URL for detail views on TYPO3 9, but the detail view returns a 404 error: "TYPO3\CMS\Core\Error\Http\PageNotFoundException: The requested page does not exist"

This is the config.yaml:

...
routeEnhancers:
  ...
  News:
    ...
  CDP_Gemeinden:
    type: Extbase
# Pages containing list/detail-plugin
    limitToPages:
      - 43336
      - 11082
# From registerPlugin @ ext_tables.php
# Extension key is dvt_cdp
    extension: DvtCdp
# From configurePlugin @ ext_localconf.php
    plugin: CdpGemeinden
    routes:
      - { routePath: '/gemeinde/{gemoestat}/', _controller: 'Gemeinden::show', _arguments: {'gemoestat': 'gemoestat'} }
    defaultController: 'Gemeinden::search'
    requirements:
      gemoestat: '\d+'
    aspects:
      gemoestat:
        type: StaticRangeMapper
        start: '70100'
        end: '70999'

On pages 43336 and 11082 lies the plugin that handles both the list view and detail view. "gemoestat" is the unique ID of the city. The links to the detail view are created in the list view template:

<f:link.action arguments="{gemoestat:gemeinde.gemoestat}" action="show">

This URL works on TYPO3 9 (and TYPO 8), without the routeEnhancer:

.../?tx_dvtcdp_cdpgemeinden%5Baction%5D=show&tx_dvtcdp_cdpgemeinden%5Bcontroller%5D=Gemeinden&tx_dvtcdp_cdpgemeinden%5Bgemoestat%5D=70701&cHash=8cabee37a20f804e94e2af1e9f2ce02d

This is the URL which worked on TYPO3 8, and is now generated if I activate my routeEnhancer while also leading to a 404 error:

.../gemeinden/gemeinde/70701/

Any idea what's missing? The detail view works fine without a routeEnhancer, so I don't think the extension is the problem, but rather the routeEnhancer config.


Solution

  • With external data we need a own aspect to return the values. Try this

    config.yaml

    routeEnhancers:
      CDPGemeinden:
        type: Extbase
        extension: DvtCdp
        plugin: CdpGemeinden
        routes:
          - routePath: 'gemeinde/{gemoestat}/'
            _controller: 'Gemeinden::show'
            _arguments:
              gemoestat: 'gemoestat'
        aspects:
          gemoestat:
            type: GemoestatMapper
    

    EXT:dvt_cdp/Classes/Routing/Aspect/GemoestatMapper.php

    <?php
    namespace Dvt\Cdp\Routing\Aspect;
    
    use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
    
    /**
     * Aspect that maps external gemoestat unique ID
     */
    class GemoestatMapper implements StaticMappableAspectInterface
    {
    
        /**
         * @inheritDoc
         */
        public function generate(string $value): ?string
        {
            return $value;
        }
    
        /**
         * @inheritDoc
         */
        public function resolve(string $value): ?string
        {
            return isset($value) ? (string)$value : null;
        }
    }
    

    EXT:dvt_cdp/ext_localconf.php

    // Add routing aspect
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['GemoestatMapper'] =
        \Dvt\Cdp\Routing\Aspect\GemoestatMapper::class;