Issue Bug Closed

#95766Routing across extensions

Sven Burkert 10/25/21, 12:06 updated 09/17/26, 15:35

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.

Reviews 1

History 1521

  1. Sven Burkert commented <span data-processor="relativetime" data-value="2021-10-28T16:49:28+00:00" > 10/28/21, 16:49 </span>

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

  2. Sven Burkert commented <span data-processor="relativetime" data-value="2022-06-03T15:31:00+00:00" > 06/03/22, 15:31 </span>

    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 :)

  3. Oliver Hader commented and changed status New Needs Feedback assigned to Oliver Hader Sprint Focus On Location Sprint <span data-processor="relativetime" data-value="2022-11-03T12:23:44+00:00" > 11/03/22, 12:23 </span>

    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.

    @christophl 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!

  4. Christoph Lehmann commented <span data-processor="relativetime" data-value="2022-11-04T10:27:09+00:00" > 11/04/22, 10:27 </span>

    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.

  5. Oliver Hader commented <span data-processor="relativetime" data-value="2022-11-12T07:58:40+00:00" > 11/12/22, 07:58 </span>

    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.

  6. Christoph Lehmann commented <span data-processor="relativetime" data-value="2022-11-16T08:50:50+00:00" > 11/16/22, 08:50 </span>

    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
  7. Oliver Hader commented <span data-processor="relativetime" data-value="2022-11-16T10:56:06+00:00" > 11/16/22, 10:56 </span>

    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.

  8. Gerrit Code Review pushed patch set 1 for main to change 77181 status Accepted Under Review <span data-processor="relativetime" data-value="2022-12-17T09:35:43+00:00" > 12/17/22, 09:35 </span>

  9. Christoph Lehmann commented <span data-processor="relativetime" data-value="2022-12-17T10:13:38+00:00" > 12/17/22, 10:13 </span>

    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.