Issue Bug Closed

#102505wrong routing after succesful call of an action in extbase-controller (with example-Extension)

Dieter Dr. Porth 11/24/23, 10:23 updated 10/06/26, 19:16

Description

I have a form, which contains more than one pages. The user should be allowed to bookmark every page of the form, so that he can finish his work at the next day. TYPO3 did not produce the correct link in the browser-adressline.

Reproduce the unexpected routing
1. Install Extension (plus TYPO3 11 and plus your own sitepackage i.e. with composer as `“monsun/bugtest”: “^1.0”`
2. Define routing in site-Config (see fragment in /bugtest/SiteConfig/sites/bugtest/config.yaml)
3. Update models in Database
4. Add Plugin “bugtest_routingtest” on testpage
5. Open Testpage in the frontend.
6. Create a new Testmodel.
7. Use the edit-Link in the list-view.
8. Press the button ‘update and go to EditTwo-view/action’ in the edit-view
After doing step 8 you will arrive the editTwo-View. The browser will show an unreadable link in its adressline. The link looks something like this `https://mypage.ddev.site/testrouting?tx_bugtest_routingtest%5Baction%5D=update&tx_bugtest_routingtest%5Bcontroller%5D=Testmodel&cHash=caf03268fea2493bc9302787200df133`
I expected a link, which looks something like ‘this https://mypage.ddev.site/testrouting/bugedittwo/1?cHash=dbe3b40227268c9b4619ce5c12e03ebe’.
(TYPO3 cann prdouce this link `https://one-job.ddev.site/testrouting/bugedittwo/1?cHash=dbe3b40227268c9b4619ce5c12e03ebe` expected for EditTwo-Action. See the generated link in the plugin-template.)

The automatically generated link shows, that the site-configuration seems to work correctly. The routing generation in the rendering-process of the plugin seems to be wrong.

Remark: If you remove the `action=”update”` in the <f:form> in `Edit.html` and/or `EditTwo.html`, TYPO3 will produce a link something like the following `https://one-job.ddev.site/testrouting/list`, which is not really helpful.</f:form>

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

Files 2

History 4

  1. Stefan Bürk commented <span data-processor="relativetime" data-value="2024-01-16T01:33:50+00:00" > 01/16/24, 01:33 </span>

    The routes are not really correct in the example extension
    site configuration. Therefore, I advise you to read the
    documentation regarding the routing and the extbase route
    type and the required options [1].

    All of the routes are missing a aspect mapping for the
    argument `model` to a extbase table and slug field. Without
    it it won’t work. On top of that, your model is missing a
    slug field. So you should add that first in the `ext_tables.sql`
    and as a `tca field` – for example a `path_segment` field [2].

    Than, your site configuration routing should be look like
    following:

    routeEnhancers:
      testbug:
        type: Extbase
        limitToPages:
          - 74
        extension: Bugtest
        plugin: routingtest
        routes:
          -
            routePath: '/list/'
            _controller: 'Testmodel::list'
          -
            routePath: '/bugedit/{model}'
            _controller: 'Testmodel::edit'
            _arguments:
              model: testmodel
          -
            routePath: '/bugedittwo/{model}'
            _controller: 'Testmodel::editTwo'
            _arguments:
              model: testmodel
          -
            routePath: '/bugupdate/{model}'
            _controller: 'Testmodel::update'
            _arguments:
              model: testmodel
          -
            routePath: '/bugupdate/{model}'
            _controller: 'Testmodel::show'
            _arguments:
              model: testmodel
          -
            routePath: '/bugdelete/{model}'
            _controller: 'Testmodel::show'
            _arguments:
              model: testmodel
          -
            routePath: '/bugcreate/'
            _controller: 'Testmodel::create'
          -
            routePath: '/bugnew/'
            _controller: 'Testmodel::new'
        defaultController: 'Testmodel::list'
        aspects:
          model:
            type: PersistedAliasMapper
            tableName: tx_bugtest_domain_model_testmodel
            routeFieldName: path_segment 

    As a general hint, ensure not to use the
    `features.skipDefaultArguments` setting for
    your plugin.

    # extension ext_tables.sql 
    CREATE TABLE tx_bugtest_domain_model_testmodel(
      path_segment varchar(2048),
      KEY path_segment (path_segment(127))
    );

    and the TCA example for that field and your table (partly)

    [
        'columns' => [
            'path_segment' => [
                'exclude' => 1,
                'label' => 'slug_1',
                'description' => 'field description',
                'config' => [
                    'type' => 'slug',
                    'generatorOptions' => [
                        'fields' => [
                            'input_1',
                            'input_2',
                        ],
                        'fieldSeparator' => '/',
                        'prefixParentPageSlug' => true,
                        'replacements' => [
                            '/' => '',
                        ],
                    ],
                    'fallbackCharacter' => '-',
                    'eval' => 'uniqueInSite',
                    'default' => '',
                ],
            ],
        ],
    ]

    [1] https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Routing/AdvancedRoutingConfiguration.html#extbase-plugin-enhancer
    2 https://docs.typo3.org/m/typo3/reference-tca/11.5/en-us/ColumnsConfig/Type/Slug/Index.html

  2. Dieter Dr. Porth commented and changed attached bugtest.zip <span data-processor="relativetime" data-value="2024-01-19T11:50:15+00:00" > 01/19/24, 11:50 </span>

    Your suggestions didn’t solve the problem. I also have incorrect behavior with your instructions.
    Not even the links to the forms worked with the aspects.
    (See modified extension). (Cause?: The data records are written to page 0 by the plugin.)

    Without the aspects, the UID is adopted as a value, which from my understanding should also be standard behavior.

    So in my version I can define links that point directly to the `Edit` form or `EditTwo` form. But as soon as I call up the corresponding form using the button with the corresponding action value in the form, the corresponding link is not displayed as a result in the address bar of the browser.
    All links in the list-view works fine, so I think, the configuration is correct.

    To call up the form `editTwo`, I would have expected the following link in adressline of the browser, analogous to the link in the list view:
    https://bugtest.ddev.site/bereich-personal/stelle-ausschreiben/bugtest/bugedittwo/1

    When I enter the attribute `action=“update”` in Edit’s template for f:form, I found the incorrect URL in the address line
    https://bugtest.ddev.site/bereich-personal/stelle-ausschreibe/bugtest?tx_bugtest_routingtest%5Baction%5D=update&tx_bugtest_routingtest%5Bcontroller%5D=Testmodel&cHash=caf03268fea2493bc9302787200df133
    Incorrect because the UID of the element to be updated is missing.

    If I remove the action=“update” attribute from f:form in the ‘edit’ template, then I found the meaningless URL (default Url) in the browser’s address line
    https://bugtest.ddev.site/bereich-personal/stelle-ausschreiben/bugtest/list

  3. Georg Ringer commented and changed status New Closed <span data-processor="relativetime" data-value="2026-10-06T19:16:02+00:00" > 10/06/26, 19:16 </span>

    Thanks for the detailed report and the example extension. I had a look at bugtest.zip and this is expected behaviour, not a routing bug, so I am closing the issue.

    What happens

    • In Edit.html and EditTwo.html the form is rendered as <f:form name="testmodel" object="{testmodel}">, without action or arguments.
    • The target action is selected by <f:form.button name="action" value="editTwo">. This value is sent in the POST body, not in the URL.
    • The browser address bar always shows the URL of the form’s action attribute, i.e. the URL the POST request was sent to:
      • without action="update" this is the default route (/list),
      • with action="update" the URL only contains action=update&controller=Testmodel. The model is submitted via the form fields, so the model argument is missing in the URL. No route with {model} can match, and the enhancer correctly falls back to query parameters.
    • Extbase then renders the requested action directly in that POST request. Without a redirect, the server cannot change the URL shown in the browser.

    The links in the list view work because they are GET links that carry the model argument.

    How to get bookmarkable URLs

    Use the Post/Redirect/Get pattern: submit the form to an action that persists the object, and redirect to the target action afterwards. The redirect URL is generated by the route enhancer and ends up in the address bar:

    public function updateAction(Testmodel $testmodel): ResponseInterface
    {
        $this->testmodelRepository->update($testmodel);
        return $this->redirect('editTwo', null, null, ['testmodel' => $testmodel]);
    }

    If several buttons should lead to different steps, pass the desired next step as an additional argument and choose the redirect target in updateAction accordingly.

    For further questions on how to implement this, please use the TYPO3 Slack (#typo3-cms).