0

I have a problem with routing and tx_news in TYPO3 9.5. I have tried all the official examples, but the problem still exists and I can't find out why.

Id' like to have URL like:

...home/news/detail/project-lounge-movetia-2

But I get:

...home/news/detail/project-lounge-movetia-2?tx_news_pi1[day]=11&tx_news_pi1[month]=12&tx_news_pi1[year]=2019&cHash=8fd7057d32ae3e3810b76f0bf4a06e39

The config is standard:

routeEnhancers:
  News:
    type: Extbase
    limitToPages:
      - 40
      - 54
      - 55
    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: '40'
    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
    requirements:
      page: '\d+'

The newstitle gets correctly "enhanced", but the rest is still there (hash, id, etc) I have no clue why this happens. I read the manual about routing a lot of times, but I don't get it. :(

biesior
  • 55,576
  • 10
  • 125
  • 182
Phil
  • 3
  • 3

2 Answers2

1

It should contain little bit more as showed in their documentation

routeEnhancers:
  News:
    type: Extbase
    limitToPages:
      - 104
    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

Unwanted params

Actually date params like &tx_news_pi1[day]=20&tx_news_pi1[month]=7 are NOT default ones, which mean that you copied some TS snippet, which includes it or maybe some of your co-workers put it there.

According to News' Humane readable dates documentation search for plugin.tx_news.settings.link.hrDate node in your TypoScript and modify or remove it to get rid date params in single-view links.

Eventually, if you want to keep them, but with human-readable URLs, take a look into the newest documentation of the ext:news which has a sample for proper dates routing with aspects.

biesior
  • 55,576
  • 10
  • 125
  • 182
  • Hi biesior, thanks for commenting. I have more code, I just showed the important stuff. But I edit my post now to include all Route enhancers. – Phil Jul 24 '20 at 09:13
  • Did you try to add `date-month`, `date-year` aspects as mentioned [in the documentation](https://docs.typo3.org/p/georgringer/news/8.3/en-us/AdministratorManual/BestPractice/Routing/Index.html)? – biesior Jul 24 '20 at 09:26
  • @Phil, see [answer to similar question](https://stackoverflow.com/a/57523969/1066240) – biesior Jul 24 '20 at 09:30
  • Thanks biesior! The thing is, the exact same yaml config works in another site. I can literally copy&paste it and it works as expected. So there must be something wrong other than the yaml config, but what..? Can the Extension Builder interfere? – Phil Jul 24 '20 at 11:21
  • Does other instance also uses [day], [month], [year] params in news? – biesior Jul 24 '20 at 11:26
  • No, there's no {month} or {day} in the raw url of tx_news on the testsite! So the question must be: Why do all these params appear, how do I get rid of them in the raw URL? &tx_news_pi1[day]=20&tx_news_pi1[month]=7 – Phil Jul 24 '20 at 12:00
  • @Phil, take a look into my last edit, section **Unwanted params**. – biesior Jul 24 '20 at 20:15
0

I have found the solution. The problem was not the routing, but the raw news URL contained all the additional params {day}{month}{year}. The following SETUP setting turns this off:

plugin.tx_news.settings.link.hrDate = 0

By disabling it, the raw URl generated looks like this: ?tx_news_pi1[action]=detail&tx_news_pi1[controller]=News&tx_news_pi1[news]=486&cHash=

It works now perfectly. Thanks to biesior for pushing me to the solution!

Phil
  • 3
  • 3