Bug #87337

ExtbasePluginEnhancer does not use a custom controller configuration

Added by Guido Schmechel 9 months ago. Updated 7 months ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
Link Handling, Site Handling & Routing
Target version:
-
Start date:
2019-01-05
Due date:
% Done:

100%

TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

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'

Related issues

Related to TYPO3 Core - Bug #87668: Revert "ExtbasePluginEnhancer does not use a custom controller configuration" Closed 2019-02-07

Associated revisions

Revision 977ed578 (diff)
Added by Guido Schmechel 8 months ago

[BUGFIX] Set controller in ExtbasePluginEnhancer

If the controller of a route in a routeEnhancer differs
from the default controller, it will now be used for the
generation of enhancers.

Resolves: #87337
Releases: master, 9.5
Change-Id: Iea3d15bbc99cb17c640e6a4824d3dd42176295d1
Reviewed-on: https://review.typo3.org/59343
Tested-by: TYPO3com <>
Reviewed-by: Alexander Grein <>
Tested-by: Alexander Grein <>
Reviewed-by: Richard Haeser <>
Reviewed-by: Benni Mack <>
Tested-by: Benni Mack <>

Revision 3b11984b (diff)
Added by Guido Schmechel 8 months ago

[BUGFIX] Set controller in ExtbasePluginEnhancer

If the controller of a route in a routeEnhancer differs
from the default controller, it will now be used for the
generation of enhancers.

Resolves: #87337
Releases: master, 9.5
Change-Id: Iea3d15bbc99cb17c640e6a4824d3dd42176295d1
Reviewed-on: https://review.typo3.org/59657
Tested-by: TYPO3com <>
Reviewed-by: Benni Mack <>
Tested-by: Benni Mack <>

History

#1 Updated by Gerrit Code Review 9 months 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

#2 Updated by Alexander Grein 8 months ago

A few notes to this route enhancer config example:

#3 Updated by Gerrit Code Review 8 months 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

#4 Updated by Guido Schmechel 8 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#5 Updated by Benni Mack 8 months ago

  • Related to Bug #87668: Revert "ExtbasePluginEnhancer does not use a custom controller configuration" added

#6 Updated by Oliver Hader 8 months 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 existing applyControllerActionValues) based on defaultController
    • if both parameters action and controller are empty - set both (like applyControllerActionValues)
    • if action is set, but controller is empty - just upgrade empty controller

#7 Updated by Gerrit Code Review 8 months 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

#8 Updated by Gerrit Code Review 8 months 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

#9 Updated by Guido Schmechel 7 months 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.

#10 Updated by Oliver Hader 7 months 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/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.

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) - probably PoiController::listAction

So I'm wondering why routing should introduce a new specific behavior which Extbase does not support.

#11 Updated by Guido Schmechel 7 months 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 :-)

Also available in: Atom PDF