Bug #87337
closedExtbasePluginEnhancer does not use a custom controller configuration
100%
Description
Context
I have a standard extbase plugin. Actions are list, detail and city.
Problem
If defaultController and _controller do not match from a route, the URL will not build up cleanly. In my case, he always uses "list" to generate the URL.
Solution
When verifying each configuration in the ExtbasePluginEnhancer, the controller will not overwrite the current configuration. Only the default controller is used.
if (!empty($configuration['_controller'])) {
$this->applyControllerActionValues(
$configuration['_controller'],
$originalParameters[$this->namespace]
);
}
Route Enhancer config
routeEnhancers:
DetailPoi:
type: Extbase
extension: AyacooPoi
plugin: Poi
routes:
- { routePath: 'restaurant/{slug}', _controller: 'Poi::detail', _arguments: {'slug' : 'poi'} }
- { routePath: 'stadt/{cityTitle}', _controller: 'Poi::city', _arguments: {'cityTitle' : 'city'} }
defaultController: 'Poi::list'
requirements:
poi: '\d+'
city: '\d+'
aspects:
slug:
type: PersistedAliasMapper
tableName: 'tx_ayacoopoi_domain_model_poi'
routeFieldName: 'slug'
cityTitle:
type: PersistedAliasMapper
tableName: 'tx_ayacoopoi_domain_model_poi'
routeFieldName: 'city'
Updated by Gerrit Code Review over 5 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59343
Updated by Alexander Grein over 5 years ago
- the quotes are imho only neccesary if a key or value contains spaces or other special chars like "{" or "}"
- the requirements definition in this example should look like this:
requirements: slug: \d+ cityTitle: \d+
- if the city of the cityTitle aspect contains spaces like "New York City", the generated link would look like "stadt/New%20York%20City". I think you wouldn't like this. To get links like stadt/new-york-city, you should use the PersistedPatternMapper instead. An example can be found here: https://docs.typo3.org/typo3cms/extensions/core/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html#persistedpatternmapper
Updated by Gerrit Code Review over 5 years ago
Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59657
Updated by Guido Schmechel over 5 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 977ed578d04a3c2094cdad3207b5d9f86322f326.
Updated by Benni Mack over 5 years ago
- Related to Bug #87668: Revert "ExtbasePluginEnhancer does not use a custom controller configuration" added
Updated by Oliver Hader over 5 years ago
Base scenario¶
Given the following configuration
routes: - { routePath: 'restaurant/{slug}', _controller: 'Poi::detail', _arguments: {'slug' : 'poi'} } - { routePath: 'stadt/{cityTitle}', _controller: 'Poi::city', _arguments: {'cityTitle' : 'city'} } defaultController: 'Poi::list'
Having the following parameters &tx_ayacoopoi_poi[action]=city&...
will always use Poi::list
(since tx_ayacoopoi_poi[controller]
is not set).
After 977ed578d04a3c2094cdad3207b5d9f86322f326¶
Overriding parameters with _controller
(e.g. Poi::detail
) values will result in overriding parameters with &tx_ayacoopoi_poi[controller]=Poi&tx_ayacoopoi_poi[action]=detail
- which does not reflect the real process in comparing the originally given controller/action parameters anymore.
Approach¶
- revert 977ed578d04a3c2094cdad3207b5d9f86322f326
- reimplement change like the following
- introduce new
upgradeControllerActionValues
(next to existingapplyControllerActionValues
) based ondefaultController
- if both parameters
action
andcontroller
are empty - set both (likeapplyControllerActionValues
) - if
action
is set, butcontroller
is empty - just upgrade emptycontroller
- introduce new
Updated by Gerrit Code Review over 5 years ago
- Status changed from Resolved to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59659
Updated by Gerrit Code Review over 5 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/59659
Updated by Guido Schmechel about 5 years ago
DetailPoi:
type: Extbase
extension: AyacooPoi
plugin: Poi
routes:
- routePath: '{slug}'
_controller: 'Poi::detail'
_arguments:
slug: poi
- routePath: '{cityDb}/{postalDb}'
_controller: 'Poi::search'
_arguments:
postalDb: postal
cityDb: city
defaultController: 'Poi::list'
requirements:
poi: '[0-9]+'
city: '.*'
postalDb: '[0-9]+'
aspects:
slug:
type: PersistedAliasMapper
tableName: tx_ayacoopoi_domain_model_poi
routeFieldName: slug
postalDb:
type: PersistedAliasMapper
tableName: tx_ayacoopoi_domain_model_postal
routeFieldName: postal
cityDb:
type: PersistedAliasMapper
tableName: tx_ayacoopoi_domain_model_postal
routeFieldName: slug
Given there is a "search" page with a plugin/flexform with can handle list, search and detail Action. (Poi->list;Poi->detail;Poi->city;Poi->search)
Building these links via Fluid:
index.php?tx_ayacoopoi_poi[poi]=123&tx_ayacoopoi_poi[action]=detail => www.example.com/search/slugvalue-123
index.php?tx_ayacoopoi_poi[postal]=50667&tx_ayacoopoi_poi[city]=cologne => www.example.com/search/cologne/50667
Result after PatchSet 2:
Generating links:
index.php?tx_ayacoopoi_poi[poi]=123 => www.example.com/search/slugvalue-123
index.php?tx_ayacoopoi_poi[postal]=50667&tx_ayacoopoi_poi[city]=cologne => www.example.com/search/?tx_ayacoopoi_poi[postal]=50667&tx_ayacoopoi_poi[city]=cologne
If you can see: The problem is the generating of the second link. There is no given action via <f:link.page> and so it use the default Controller, although the right action was set in the route. Because of that I had read out the configuration in the for loop and overwrite it.
Updated by Oliver Hader about 5 years ago
Guido Schmechel wrote:
[...]
Building these links via Fluid:
index.php?tx_ayacoopoi_poi[poi]=123&tx_ayacoopoi_poi[action]=detail => www.example.com/search/slugvalue-123
index.php?tx_ayacoopoi_poi[postal]=50667&tx_ayacoopoi_poi[city]=cologne => www.example.com/search/cologne/50667Result after PatchSet 2:
Generating links:
index.php?tx_ayacoopoi_poi[poi]=123 => www.example.com/search/slugvalue-123
index.php?tx_ayacoopoi_poi[postal]=50667&tx_ayacoopoi_poi[city]=cologne => www.example.com/search/?tx_ayacoopoi_poi[postal]=50667&tx_ayacoopoi_poi[city]=cologneIf you can see: The problem is the generating of the second link. There is no given action via <f:link.page> and so it use the default Controller, although the right action was set in the route. Because of that I had read out the configuration in the for loop and overwrite it.
Thanks for the explanation & I see what you're aiming for. But the 2nd URI won't work with plain Extbase (without having routing in place).
index.php?tx_ayacoopoi_poi[postal]=50667&tx_ayacoopoi_poi[city]=cologne
- no
...[action]=search
parameter is given - (plain) Extbase will use the default controller-action pair (as configured in
ext_localconf.php
) - probablyPoiController::listAction
So I'm wondering why routing should introduce a new specific behavior which Extbase does not support.
Updated by Guido Schmechel about 5 years ago
Thanks for your feedback. You're right, the parameter is deliberately missing and in the first step I also asked for misconfiguration ;-)
For me it was a point from the documentation. I build the link with two parameters and add the "controller" and "action" over the route. So my expectation was that it would be taken from there. If this were not wished, then I wonder about the sense of the controller within the route. Maybe you can explain?
Alternatively we just have to modify the docs :-)
Updated by Gerrit Code Review over 4 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/59659
Updated by Gerrit Code Review over 4 years ago
Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62231
Updated by Oliver Hader over 4 years ago
- Status changed from Under Review to Resolved
Applied in changeset 4f12e25ea343fe5969ba25367303355241165688.