Migrating von TYPO3 8.7 to 9.5 I need to replace an old realurl-configuration to match the new routing:
Old-Realurl Config: Custom Segment for Country after language:
'preVars' => array(
array(
'GETvar' => 'L',
'valueMap' => array(
'en' => '0', // darf nicht auskommentiert sein!
'de' => '1',
'pl' => '2',
...
array(
'GETvar' => 'C',
'valueMap' => array(
'de'=>'1',
'ch'=>'2',
'ch'=>'3',
I tried "simple" route enhancer inTYPO3 9.5 Site Config:
languages:
-
title: English
enabled: true
languageId: 0
base: /en/
typo3Language: default
locale: en_US.UTF-8
iso-639-1: en
navigationTitle: English
hreflang: en-us
direction: ltr
flag: us
-
title: German
enabled: true
base: /de/
typo3Language: de
locale: de_DE.UTF-8
iso-639-1: de
navigationTitle: ''
hreflang: ''
direction: ''
fallbackType: fallback
fallbacks: ''
flag: de
languageId: '1'
rootPageId: 1
routes: { }
routeEnhancers:
Country:
type: Simple
routePath: '/{Country}'
defaults:
requirements:
C: '[1-21]'
aspects:
Country:
type: StaticValueMapper
map:
de: 1
ch: 2
But the country segments wont appear between Language and main-slug: OLD URLS: www.mydomain.com/de/ch/home/
With my rout-enhancer config (above): www.mydomain.com/de/home/ch/
Does anyone know how I can achive this custom segment and let it appear at the right place ?
Many Thanks for any hints
A route enhancer adds something after the Page URL. However, we had a similar scenario. Here is what I had to do in order to make it work:
Build a custom middleware (after the language is resolved, and a SiteRouteResult is available in the PSR-7 Request in a PSR-15 middleware) This middleware then takes the "tail" of the SiteRouteResult, and resolves the argument based on a given static list (like it was available in the list). After that, I created a new SiteRouteResult object with that pathSegment removed from the tail. Keep in mind that it might be very useful to store the resolved argument as a "variant" of the page, thus, effectively hooking into TSFE where the createHashBase() is built to also calculate in this variable.
I recommend storing this string in the request as custom property, or as a custom TSFE property.
It is NOT possible to resolve a "prePathVar" with a RouteEnhancer, as the right route enhancers are only selected AFTER the page was found. If your URL has "/ch/home" TYPO3 PageRouter can NOT find the correct page.
Create a RouteEnhancer that acts like a decorator (see PageType enhancer). However, the decorator does not need does not "undecorate" / "resolve" an URL (do nothing). This gets tricky if you also use the PageTypeDecorator, as you can only have one, so you might need to extend the one from Core, if you also need to map typeNums.
In any case, the custom Enhancer can then prefix the generated route with the static map depending if the type is given.
Hope that helps!