1

I´m currently working on a project which uses the news-extension on various pages. To get rid of cryptic URLs, i added the following code to my config.yaml:

routeEnhancers:
  News:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/{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

This gives me the result i want for some pages but for others, it throws a FE-Error:

(1/1) Symfony\Component\Routing\Exception\InvalidParameterException
Parameter "tx_news_pi1__news" for route "tx_news_pi1_0" must match ".+" ("" given) to generate a corresponding URL.

This error appears on some pages, which include the news-plugin and should show a list view. The weird part is, that as this is a regular page, it should have a regular URL which perfectly works without the code mentioned above. Even more weird is the fact, that i can reach the news-detail page when manually entering the desired speaking-URL. So URL-rewriting for news detail views works on every page but it breaks other list view pages´ URLs that have worked before.

I spent a few hours trying to figure out where the error comes from and found out:

  • if i change settings.categoryConjunction from OR to AND, the list view works but logically shows wrong results
  • same thing happens when i change settings.categories i.e when i add a complete category instead of a subcategory

Click me to see backend configuration

Conclusion:

  • myproject.local/somepagewithnews works
  • myproject.local/somepagewithnews/detail/articleWithSpeakingUrl works
  • myproject.local/anotherpagewithnews doesnt work
  • myproject.local/anotherpagewithnews/articleWithSpeakingUrl works. Note that there appears no /detail/ in between. Adding it will result in a Page does not exist-Error.

Without the code, every page and every news article works with the difference that the article (not the pages with list views) have cryptic URLs.

I hope my issue is understandable and someone here can help me as this is driving me nuts. Thanks in advance!!

  • The problem is that your enhancer works for every tx_news_pi1 plugin and assumes it to be News::detail. You should either add routes for your list pages or (simpler) just add `limitToPages: []` – Jonas Eberle Feb 19 '21 at 08:58
  • Thanks for your answer! I already tried that but unfortunately the same error occurs when accessing the corresponding list-page. (List page has ID 46, Detail page has 142). But i cant access 46 when i put `limitToPages: [142]` – ItHurtsWhenIP Feb 19 '21 at 10:16
  • Have you tried `limitToPages: [46,142]` already? – User366 Feb 20 '21 at 13:51
  • Doesn´t work either, unfortunately – ItHurtsWhenIP Feb 22 '21 at 06:56

4 Answers4

3

(1/1) Symfony\Component\Routing\Exception\InvalidParameterException Parameter "tx_news_pi1__news" for route "tx_news_pi1_0" must match ".+" ("" given) to generate a corresponding URL.

The exception says the parameter to generate URL is empty "". You have configured the YAML file to get value from path_segment field to generate url.

news_title: type: PersistedAliasMapper tableName: tx_news_domain_model_news routeFieldName: path_segment

Means some of the records have an empty path_segment/slug. That's why exception keeps occurring in some pages only. Check if all the news records has value in path_segment field.

  • Livesaver! Indeed I had several empty path_segments and after I generated them again the error message disappeared. Would be nice to have a fallback. For example the uid of a news. Is this possible? – Christian Michael Jan 10 '22 at 16:43
0

This configuration means that EVERY page of your site must have news item title. You need to limit to a detail page pid by using limitToPages:

routeEnhancers:
  News:
    limitToPages: [10]
User366
  • 765
  • 4
  • 9
  • Thanks for your answer! I already tried that but unfortunately the same error occurs when accessing the corresponding list-page. (List page has ID 46, Detail page has 142). But i cant access 46 when i put `limitToPages: [142]` – ItHurtsWhenIP Feb 19 '21 at 10:15
0

You can add the route for list view:

routes:
      - routePath: '/'
        _controller: 'News::list'

In the documentation of EXT:news you can find all about the configuration of routes: https://docs.typo3.org/p/georgringer/news/8.5/en-us/AdministratorManual/BestPractice/Routing/Index.html?highlight=routeenhanc

Full configuration from doc:

routeEnhancers:
  News:
    type: Extbase
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/'
        _controller: 'News::list'
      - routePath: '/page-{page}'
        _controller: 'News::list'
        _arguments:
          page: '@widget_0/currentPage'
      - routePath: '/{news-title}'
        _controller: 'News::detail'
        _arguments:
          news-title: news
      - routePath: '/{category-name}'
        _controller: 'News::list'
        _arguments:
          category-name: overwriteDemand/categories
      - routePath: '/{tag-name}'
        _controller: 'News::list'
        _arguments:
          tag-name: overwriteDemand/tags
    defaultController: 'News::list'
    defaults:
      page: '0'
    aspects:
      news-title:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_news
        routeFieldName: path_segment
      page:
        type: StaticRangeMapper
        start: '1'
        end: '100'
      category-name:
        type: PersistedAliasMapper
        tableName: sys_category
        routeFieldName: slug
      tag-name:
        type: PersistedAliasMapper
        tableName: tx_news_domain_model_tag
        routeFieldName: slug
Heinz Schilling
  • 2,177
  • 4
  • 18
  • 35
  • Thx for the answer! But it just won't work..:( I tried dozens of combinations and possibilities but as soon as i manage to get the list-page working, the detail view has a cryptic URL. There seems to be a problem with the controllers, because if i set `defaultController` to `'News::detail'`, i get speaking URLs, if i set it to `'News::List'`, i can access the list view, but have cryptic URLs for detail page, although the controller for `'routePath: '/{news_title}'` is set to `'News::detail'` – ItHurtsWhenIP Feb 22 '21 at 07:05
  • You have to config both controllers. Have a look at the doc. Maybe you have to update TYPO3 and EXT:news to the latest version. I extend my answer. – Heinz Schilling Feb 22 '21 at 09:19
0

Got the same issue.

It seams the problem is

link {
    skipControllerAndAction = 1
}

in the tx_news configuration. Simply remove it.

Found this solution here: TYPO3 News routing not working properly...

mbieh
  • 21
  • 4