Search code examples
typo3typo3-9.xtx-newssymfony-routing

Routing exception after upgrading to TYPO3 v9.5.14


After upgrading to TYPO3 v9.5.14 our detail pages for news crash with the exception

Symfony\Component\Routing\Exception\InvalidParameterException

Parameter "p88bd715a41119d0e8087a5d19cb049" for route "tx_news_pi1_1" must match "[^/]++" ("" given) to generate a corresponding URL.

What's going on?

The site used this configuration:

  NewsTagPlugin:
    type: Extbase
    limitToPages: [14]
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/{tag-name}'
        _controller: 'News::list'
        _arguments:
          tag-name: 'overwriteDemand/tags'
      - routePath: '/{tag-name}/page/{page}'
        _controller: 'News::list'
        _arguments:
          tag-name: 'overwriteDemand/tags'
          page: '@widget_0/currentPage'
          requirements:
            page: '\d+'
    defaultController: 'News::list'
    defaults:
      page: ''
    aspects:
      page:
        type: IntegerMapper
        start: 1
        end: 5000
      tag-name:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_tag
        routeFieldName: slug

Solution

  • 1) Superfluous mapping

      NewsTagPlugin:
        ...
        routes:
          ...
          - routePath: '/{tag-name}/page/{page}'
            _controller: 'News::list'
            _arguments:
              tag-name: 'overwriteDemand/tags'
              page: '@widget_0/currentPage'
              requirements:
                page: '\d+'
    
    • _arguments defines a mapping for route parameter and internal variables (e.g. as query parameter`
    • requirements is wrong here, since it shall not be used as argument mapping
    • parameter requirements need to be defined on the root level of NewsTagPlugin

    2) Invalid empty default value

      NewsTagPlugin:
        ...
        routes:
          ...
          - routePath: '/{tag-name}/page/{page}'
          ...
        defaults:
          page: ''
        aspects:
          ...
    
    • defaults was not applied prior to TYPO3 v9.5.14 and addressed in https://review.typo3.org/c/Packages/TYPO3.CMS/+/60361
    • the empty default value for parameter page does not make much sense and would lead to an URL like /some-tag/page/ which is causing the error message shown in the answer
    • the default value should be page: 1
    • in case the parameter should be omitted in the URL (e.g. having /some-tag/page/) this needs to be defined explicitly using {!page} in the route path

    References

    Adjusted enhancer configuration

      NewsTagPlugin:
        type: Extbase
        limitToPages: [14]
        extension: News
        plugin: Pi1
        routes:
          - routePath: '/{tag-name}'
            _controller: 'News::list'
            _arguments:
              tag-name: 'overwriteDemand/tags'
          - routePath: '/{tag-name}/page/{!page}'
            _controller: 'News::list'
            _arguments:
              tag-name: 'overwriteDemand/tags'
              page: '@widget_0/currentPage'
        defaultController: 'News::list'
        defaults:
          page: 1
        aspects:
          page:
            type: IntegerMapper
            start: 1
            end: 5000
          tag-name:
            type: PersistedAliasMapper
            tableName: tx_news_domain_model_tag
            routeFieldName: slug
    
    • (untested) since IntegerMapper seems to be a custom aspect implementation - not being available to the public