I am trying to set up a RouteEnhacer for the TYPO3 extension web2pdf to rewrite URLs like https://example.com/subpage/?tx_web2pdf_pi1[action]=generatePdfLink&tx_web2pdf_pi1[argument]=printPage&tx_web2pdf_pi1[controller]=Pdf&cHash=123456789 to https://example.com/subpage/pdf/.
By using …
routeEnhancers:
Web2pdf:
type: Plugin
routePath: '/pdf/{argument}'
namespace: 'tx_web2pdf_pi1'
aspects:
argument:
type: StaticValueMapper
map:
1: printPage
… I already got the URLs a bit shorter:
Can the routing be optimized further so that I get the desired short URL?
I suspect an Extbase route enhancer would be better, but my attempts have all failed and no rewriting has taken place.
IMO there is no need to map controller and action, as these are default arguments, automatically handled with a proper configured enhancer. The only (non-standard / custom) argument which needs to be mapped is tx_web2pdf_pi1[argument].
Here is the extbase route enhancer, which generates /your/subpage/pdf:
routeEnhancers:
Pdf:
type: Extbase
extension: Web2pdf
plugin: Pi1
routes:
- routePath: '/{your_argument_replacement}'
_controller: 'Pdf::generatePdfLink'
_arguments:
your_argument_replacement: 'argument'
aspects:
argument:
type: StaticValueMapper
map:
pdf: 'printPage'
Tested with the following link, rendered by fluid viewhelper:
<f:link.action action="generatePdfLink"
controller="Pdf"
extensionName="Web2pdf"
arguments="{argument:'printPage'}">PDF</f:link.action>