Issue Bug Closed

#87910ExtbasePluginEnhancer won't work on same page or without page limitation

Stefan Berger 03/14/19, 12:35 updated 10/16/26, 14:56

Description

Hi,

if you define 2 ExtbasePluginEnhancer of the same extension and plugin without a page limitation or on the same page, then only the later defined PluginEnhancer will remain for route matching. We are using the newest version 9.5.5.

Here the example config without a page limitation:

routeEnhancers:
  NewsPlugin:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      - { routePath: '/news/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
    defaultController: 'News::detail'
    aspects:
      news_title:
        type: PersistedAliasMapper
        tableName: 'tx_news_domain_model_news'
        routeFieldName: 'path_segment'
  NewsListPlugin:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      - { routePath: '/list/{page}', _controller: 'News::list', _arguments: {'page': '@widget_0/currentPage'} }
    defaultController: 'News::list'
    defaults:
      page: '0'
    requirements:
      page: '\d+'
    aspects:
      page:
        type: StaticRangeMapper
        start: '1'
        end: '100'

It seems, that the name for the route collection is not unique enough: @see \TYPO3\CMS\Extbase\Routing\ExtbasePluginEnhancer::enhanceForMatching

Thanks for fixing the issue.

Reviews 0

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

History 3

  1. Lars Peter Søndergaard commented <span data-processor="relativetime" data-value="2019-05-02T10:00:12+00:00" > 05/02/19, 10:00 </span>

    I encountered this as well.

    In my case I had additionally “limitToPages” set for both enhancers, with the same page ids.

    And after digging a bit (a lot actually), I realized what the issue is:

    When “limitToPages”, “extension” and “plugin” are all the same over multiple Extbase enhancers, then the list of routes “overrides” each other. The effect is similar to an array_merge of the routes.

    So in the example above the '/list/{page}' route overrides the '/news/{news_title}' route, because they’re on the same position (index 0) of the routes list.

    Every route gets added to the RouteCollection for the current page (created in \TYPO3\CMS\Core\Routing\PageRouter::matchRequest) and in the case of the ExtbasePluginEnhancer, each route gets a key using the extension and plugin name as namespace, and an index $i, this $i value however, restarts for every new Extbase enhancer, causing enhancers with the same namespace to override each other:

    \TYPO3\CMS\Core\Routing\PageRouter::matchRequest

                $pageCollection = new RouteCollection();
                [... omitted ...]
                $enhancers = $this->getEnhancersForPage($pageIdForDefaultLanguage, $language);
                foreach ($enhancers as $enhancer) {
                    if ($enhancer instanceof RoutingEnhancerInterface) {
                        $enhancer->enhanceForMatching($pageCollection);
                    }
                }

    \TYPO3\CMS\Extbase\Routing\ExtbasePluginEnhancer::enhanceForMatching

        /**
         * {@inheritdoc}
         */
        public function enhanceForMatching(RouteCollection $collection): void
        {
            $i = 0;
            /** @var Route $defaultPageRoute */
            $defaultPageRoute = $collection->get('default');
            foreach ($this->routesOfPlugin as $configuration) {
                $route = $this->getVariant($defaultPageRoute, $configuration);
                $collection->add($this->namespace . '_' . $i++, $route);
            }
        }

    I stumbled upon this issue, because I had a case where I split the extbase enhancer over three enhancer entries, all with the same limitToPages/extension/plugin values. And because they had multiple routes, some of them worked perfectly fine, and others did not, which caused a lot of confusion on my end.

    Anyway: An easy solution (for now), is to simply merge the different routing enhancers into one.

  2. Georg Ringer commented and changed status New Closed <span data-processor="relativetime" data-value="2026-10-16T14:56:17+00:00" > 10/16/26, 14:56 </span>

    Thanks for the report and the detailed analysis, Lars Peter.

    The behaviour is still present in main: ExtbasePluginEnhancer::enhanceForMatching() restarts its counter for every enhancer instance and names the routes tx_<extension>_<plugin>_<n>. Two enhancers for the same extension and plugin therefore add routes with identical names to the RouteCollection, and the later one silently replaces the earlier one. A unit test confirms that the collection holds only two routes (default plus one) instead of three.

    This is a limitation of how the enhancer is meant to be used, not something that can be changed safely: one Extbase plugin is described by one enhancer, and all its routes belong into its routes list:

    routeEnhancers:
      NewsPlugin:
        type: Extbase
        extension: News
        plugin: Pi1
        routes:
          - { routePath: '/news/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
          - { routePath: '/list/{page}', _controller: 'News::list', _arguments: {'page': '@widget_0/currentPage'} }
        defaultController: 'News::detail'
        defaults:
          page: '0'
        requirements:
          page: '\d+'
        aspects:
          news_title:
            type: PersistedAliasMapper
            tableName: 'tx_news_domain_model_news'
            routeFieldName: 'path_segment'
          page:
            type: StaticRangeMapper
            start: '1'
            end: '100'

    Making the route names unique per enhancer would change the matching order of existing setups, in which routes of several enhancers currently override each other, and the generated URLs would depend on the order of the definitions. That is a risk for a bugfix, and the supported configuration already covers the use case.

    I’m therefore closing this as “works as designed”.

    If this is still valid for you in v14, please open a new issue and provide information how to reproduce it. Thanks!