Bug #91530
closedEmpty optional arguments throws InvalidParameterException using the ExtbasePluginEnhancer
0%
Description
Hi,
we try to migrate our old realurl setup into the new routing configurations.
Now, when we use the ExtbasePluginEnhancer for optional/empty arguments it throws the InvalidParameterException in the Symfony UrlGenerator in not cached situations for links, which will be rendered by this ExtbasePluginEnhancer:
Parameter "tx_example_pi1__category" for route "tx_example_pi1_0" must match "[^/]++" ("" given) to generate a corresponding URL.
We tried different settings like default or requirements but nothing work.
The example url: https://example.com/index.php?id=1&tx_example_pi1[category]=
Our setup is the following:
routeEnhancers: Example: type: Extbase extension: Example plugin: Pi1 limitToPages: - 1 routes: - routePath: '/category/{category_slug}' _controller: 'Category::list' _arguments: category_slug: category aspects: category_slug: type: PersistedAliasMapper tableName: sys_category routeFieldName: slug
It must be said in advance, that the old behavior was using the trailing slash, so we integrate that behavior as a ForceAppendingSlashDecorator like the example here: https://stackoverflow.com/a/53144597
We fixed the issue through and new configuration and an override of the ExtbasePluginEnhancer.
New configuration:
routeEnhancers: Example: ... optionalArguments: - tx_example_pi1__category ...
Override ExtbasePluginEnhancer:
... use TYPO3\CMS\Core\Routing\Route; use TYPO3\CMS\Extbase\Routing\ExtbasePluginEnhancer as ExtbasePluginEnhancerCore; class ExtbasePluginEnhancer extends ExtbasePluginEnhancerCore { protected function verifyRequiredParameters(Route $route, array $parameters): bool { if (parent::verifyRequiredParameters($route, $parameters)) { if (is_array($this->configuration['optionalArguments'])) { $compiledRoute = $route->compile(); $deflatedParameters = $this->deflateParameters($route, $parameters); foreach($this->configuration['optionalArguments'] as $optionalArgument) { foreach ($compiledRoute->getPathVariables() as $pathVariable) { if ( $pathVariable == $optionalArgument && ( !isset($deflatedParameters[$optionalArgument]) || $deflatedParameters[$optionalArgument] == '' ) ) { return false; } } } } } return true; } }
Please investigate this. Thanks.