routestypo3url-routingtypo3-11.x

TYPO3 v11: How to remove controller and hash from route


Paths from a custom TYPO3 extensions look like this:

https://example.com/events/detail/event-title/test-event/?tx_eventmanager_eventdisplay%5Bcontroller%5D=Event&cHash=f32fdcaf3d016b8b89861dfab5a0558d

And I want them to look like: https://example.com/events/detail/event-title/test-event/

routeEnhancer configuration looks like this:

routeEnhancers:
  EventDetail:
    type: Plugin
    routePath: '/event-title/{event}'
    namespace: tx_eventmanager_eventdisplay
    defaults:
      controller: 'Event'
    aspects:
      event:
        type: PersistedAliasMapper
        tableName: tx_eventmanager_domain_model_event
        routeFieldName: path_segment

TYPO3 version is 11.5.34

The exact same configuration produces the desired result in another extension (in another Site) from which the current one was forked years ago. It worked even without "defaults", which I added because it looked like they might help. I tried it with type: Extbase instead but that didn't work with either extension for some reason.

So there seems to be some small but crucial difference between both extensions (or environments), but both have diverged considerably - what should I look out for? Or can I fix it by some additional configuration in routeEnhancer?

I already tried narrowing it down with ChatGPT, but that didn't help much. I tried different routeEnhancer configurations that it offered, which didn't improve it. And based on its advice I compared:

All of which were identical in both extensions. Other than that its advice is very broad.


Solution

  • As Julian Hofmann suggested, controller needs to be added as a static mapping. This feels hacky but gives the desired outcome:

      EventDetail:
        type: Plugin
        dynamicPages:
          withPlugin: eventmanager_eventdisplay
        routePath: '/event-{controller}/{event}'
        namespace: tx_eventmanager_eventdisplay
        aspects:
          event:
            type: PersistedAliasMapper
            tableName: tx_eventmanager_domain_model_event
            routeFieldName: path_segment
          controller:
            type: StaticValueMapper
            map:
              title: Event