I need to beautify the urls of a framework for the presentation of historical documents (Kitodo.Presentation)
Simple replacements work, but in some cases multiple namespaces are needed, for example:
tx_dlf[id]=3506&tx_dlf[page]=2&tx_dlf[double]=0&tx_dlf_navigation[controller]=Navigation
Besides, there are places where the parameter is multipart, for example
tx_dlf_listview[searchParameter][collection]=16
or even
tx_dlf_search[searchParameter][fq][0]
At the moment I have to work with Typo3 v10, due to limitations of Kito.Presentation
Only examples with one namespace are listed in the Typo3 documentation. However, no statement is made about the number of possible namespaces.
Extract from my config.yaml
routeEnhancers:
KitodoWorkview:
type: Plugin
namespace: tx_dlf
limitToPages:
- 21
routePath: '/{id}/page-{page}'
requirements:
id: \d+
page: \d+
KitodoWorkviewDoublePagegrid:
type: Plugin
namespace: tx_dlf
limitToPages:
- 21
routePath: '/{id}/page-{page}/g-{pagegrid}-d-{double}'
default:
double: 0
pagegrid: 0
requirements:
id: \d+
page: \d+
double: 0|1
pagegrid: 0|1
KitodoHistCollectionView:
type: Plugin
namespace: tx_dlf_collection
limitToPages:
- 1
- 2
- 5
routePath: '/{action}/{controller}/{collection}'
requirements:
action: (show|main)
collection: (\d+)
controller: (Collection|ListView)
KitodoWorkviewDoublePagegridNextBack:
type: Plugin
namespace:
- tx_dlf
- tx_dlf_navigation
limitToPages:
- 212
routePath: '/{id}/page-{page}/{pagegrid}-{double}|{controller}'
default:
double: 0
pagegrid: 0
requirements:
id: '(\d+)|(https.*.xml)|(http.*xml)'
page: \d+
double: 0|1
pagegrid: 0|1
controller: (Navigation)
KitodoHistCollectionListView:
type: Plugin
namespace: tx_dlf_listview
limitToPages:
- 5
- 22
- 23
- 24
- 25
- 32
routePath: '/{action}/{controller}'
requirements:
action: (show|main)
controller: (Collection|ListView)
KitodoNavigation:
type: Plugin
namespace: tx_dlf_navigation
limitToPages:
- 21
routePath: '/controller-{controller}'
requirements:
controller: '^[a-zA-Z]{5,20}$'
Here are two working examples, derived from the very helpful answer by @Bernd Wilke, without the use of "namespaces"
...tx_dlf[id]=2&tx_dlf_navigation[controller]=Navigation ...
KitodoWorkviewDoublePagegridNextBack:
type: Simple
limitToPages:
- 21
routePath: '/{id}/page-{page}/g-{pagegrid}-d-{double}/nc-{navcontroller}'
default:
double: 0
pagegrid: 0
_arguments:
id: 'tx_dlf/id'
page: 'tx_dlf/pagegrid'
pagegrid: 'tx_dlf/pagegrid'
double: 'tx_dlf/double'
navcontroller: 'tx_dlf_navigation/controller'
requirements:
id: \d+
page: \d+
pagegrid: 0|1
double: 0|1
controller: (Navigation)
...tx_dlf_listview[searchParameter][collection]=2&tx_dlf_listview[widgetPage][currentPage]=1 ...
KitodoHistCollectionListView:
type: Simple
limitToPages:
- 5
routePath: '/list-action-{action}/list-controller-{controller}/list-collection-{searchParameter}/list-cp-{widgetPage}'
_arguments:
action: 'tx_dlf_listview/action'
controller: 'tx_dlf_listview/controller'
searchParameter: 'tx_dlf_listview/searchParameter/collection'
widgetPage: 'tx_dlf_listview/widgetPage/currentPage'
requirements:
action: (show|main)
controller: (Collection|ListView)
searchParameter: \d+
widgetPage: \d+
Multipart parameter can be handled with _arguments
which also are in the examples.
See the example for the paginator (@widget_0[currentPage]
):
routeEnhancers:
News:
type: Extbase
extension: News
plugin: Pi1
routes:
- routePath: '/page-{page}'
_controller: 'News::list'
_arguments:
page: '@widget_0/currentPage'
or the overwriting parameter:
:
- routePath: '/{tag-name}'
_controller: 'News::list'
_arguments:
tag-name: overwriteDemand/tags
With arguments you also can combine multiple parameters to one path segment, independent of parameter names and dimensions similar to your example:
routePath: '/{year}-{month}'
_controller: 'Post::listPostsByDate'
_arguments:
year: year
month: month
regarding the multiple namespaces:
I would drop namespaces and specify all parameters as multidimensional arguments.
If the namespace
option is required for type: Extbase
(I find no full documentation for it) try type: Simple
:
if you want to join: &tx_dlf[double]=0&tx_dlf_navigation[controller]=Navigation
routeEnhancers:
MySpecialRoute:
type: Simple
routePath: '{controller}-{double}/'
_arguments:
controller: 'tx_dlf_navigation/controller`
double: 'tx_dlf/double'
(you can add and maybe should add further configuration like defaults
and requirements
)