Project

General

Profile

Actions

Bug #95766

open

Routing across extensions

Added by Sven Burkert over 2 years ago. Updated 9 months ago.

Status:
Under Review
Priority:
Should have
Assignee:
Category:
Link Handling, Site Handling & Routing
Target version:
-
Start date:
2021-10-25
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
Tags:
realurl, routeEnhancer, speaking url, slug
Complexity:
Is Regression:
Sprint Focus:

Description

I can't believe TYPO3 has this limitation but it seems so: has every route to be unique across all plugins of all extensions?

Given:
  1. Extension EXT:news with a news record with title "foo"
  2. Extension EXT:myext with a record with title "foo"
Expectation:
  1. News record is shown on url /news/details/foo/
  2. Record is shown on url /myext/details/foo/
Actual:
  1. News record is shown
  2. Record of EXT:myext isn't found

The controller action of EXT:myext is called with "null" instead of the object. When switching the routeEnhancers configuration in the site configuration (configuration EXT:news on last position) the record of EXT:myext is shown, but the news record not.


Related issues 1 (0 open1 closed)

Has duplicate TYPO3 Core - Bug #93727: Extbase Routing Enhancer with several routes doesn't work when routes use different controllerClosed2021-03-12

Actions
Actions #2

Updated by Sven Burkert over 2 years ago

Yes, but this isn't a solution for pages where editors can use the plugin on every page they want to.

Actions #4

Updated by Sven Burkert almost 2 years ago

Thank you, this could help, nice code <3

I will have a look at it the next time I'm getting problems with that.

I keep this ticket opened until this is fixed by TYPO3 CMS Core :)

Actions #5

Updated by Oliver Hader over 1 year ago

  • Status changed from New to Needs Feedback
  • Assignee set to Oliver Hader
  • Sprint Focus set to On Location Sprint

How did the route enhancer configuration look like? I guess /news and /myext are pages, thus the route part would have been like '/details/{title}/', correct?

That's a usual problem with that ambiguity.

@Christoph Lehmann Thanks for sharing the code snippets. Can you describe a little bit, how it is supposed to work and how it should be used? Thanks in advance!

Actions #6

Updated by Oliver Hader over 1 year ago

  • Has duplicate Bug #93727: Extbase Routing Enhancer with several routes doesn't work when routes use different controller added
Actions #7

Updated by Christoph Lehmann over 1 year ago

In the following example News and Contacts have the same route path "/{news-title}" and "/{contact-title}". ExtbaseRequiringPluginOnPage in the first routeEnhancer makes it possible.

routeEnhancers:
  News:
    type: ExtbaseRequiringPluginOnPage
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/'
        _controller: 'News::list'
      - routePath: '/{news-title}'
        _controller: 'News::detail'
        _arguments:
          news-title: news
      - routePath: '/{category-name}'
        _controller: 'News::list'
        _arguments:
          category-name: overwriteDemand/categories
    defaultController: 'News::list'
    defaults:
      page: '0'
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment
      category-name:
        type: PersistedAliasMapper
        tableName: sys_category
        routeFieldName: slug

  Contacts:
    type: Extbase
    extension: SomeAddress
    plugin: ShowContact
    routes:
      - routePath: '/{contact-title}'
        _controller: 'Contact::show'
        _arguments:
          contact-title: contact
    aspects:
      contact-title:
        type: PersistedAliasMapper
        tableName: tx_some_domain_model_contact
        routeFieldName: slug

ExtbaseRequiringPluginOnPage checks if there is a news plugin on the page and depending on the result it decorates the route or not. If not, then the next route enhancer tries to decorate the route path.

So, if you have 3 different plugins having the same route path, then ExtbaseRequiringPluginOnPage needs to be used for the two beginning routeEnhancers. (Didn't tried).

routeEnhancers:
  News:
    type: ExtbaseRequiringPluginOnPage
  Contacts:
    type: ExtbaseRequiringPluginOnPage
  Events:
    type: Extbase

Using ExtbaseRequiringPluginOnPage leads to one extra SQL query per request.

Actions #8

Updated by Oliver Hader over 1 year ago

  • Status changed from Needs Feedback to Accepted
Actions #9

Updated by Oliver Hader over 1 year ago

What do you think about having a new settings for corresponding enhancers? For instance

routeEnhancers:
  News:
    type: ExtbaseRequiringPluginOnPage
    extension: News
    plugin: Pi1
    # use plugin name from settings
    requiresPluginOnPage: true
    # use specific plugin name, might be different to current enhancer settings, e.g. `tx_news_pi9`
    requiresPluginOnPage: 'news_pi9'

A further optimization would be to fetch all plugins names for the current resolved page and put those names for the plugin-check to a runtime cache.

Actions #10

Updated by Christoph Lehmann over 1 year ago

I like the solution with the new option.

But, without looking into the code, doesn't do

requiresPluginOnPage: 'news_pi9'

the same like using this?

requiresPluginOnPage: true
plugin: Pi9
Actions #11

Updated by Oliver Hader over 1 year ago

For Extbase and Plugin enhancers this is correct, for e.g. Simple enhancers it needs to be explicit.
But it would be fine for me to go with requiresPluginOnPage: true, since anything seems to be an edge case.

Actions #12

Updated by Gerrit Code Review over 1 year ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77181

Actions #13

Updated by Gerrit Code Review over 1 year ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77181

Actions #14

Updated by Christoph Lehmann over 1 year ago

Instead of using

requiresPluginOnPage: true

it's more practical to use a comma-separated list of plugins like

requiresPluginOnPage: Pi1, NewsDetail

since extensions can have multiple plugins allowing the same route.

Actions #15

Updated by Gerrit Code Review over 1 year ago

Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77181

Actions #16

Updated by Gerrit Code Review over 1 year ago

Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77181

Actions #17

Updated by Gerrit Code Review over 1 year ago

Patch set 5 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77181

Actions #18

Updated by Gerrit Code Review about 1 year ago

Patch set 6 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/77181

Actions #19

Updated by Benni Mack 9 months ago

  • Sprint Focus deleted (On Location Sprint)
Actions

Also available in: Atom PDF