Project

General

Profile

Actions

Bug #87910

open

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

Added by Stefan Berger about 5 years ago. Updated almost 5 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Link Handling, Site Handling & Routing
Target version:
-
Start date:
2019-03-14
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

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.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #88860: RouteEnhancer with two actions of one extension on one PID not workingRejected2019-07-30

Actions
Actions #1

Updated by Lars Peter Søndergaard almost 5 years ago

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.

Actions #2

Updated by Julian Stock over 4 years ago

  • Related to Bug #88860: RouteEnhancer with two actions of one extension on one PID not working added
Actions

Also available in: Atom PDF