1

Hello I found the following on a TYPO3 Slack channel as what one person was using. This snip of yaml exists at the /config/my-websitename/config.yaml...

routeEnhancers:
  NewsList:
    type: Extbase
    limitToPages: [2,20,21,22,92]
    extension: News
    plugin: Pi1
    routes:
      - routePath: '/p{page}'
        _controller: 'News::list'
        _arguments: {'page': '@widget_0/currentPage'}
      - routePath: '/{news_title}'
        _controller: 'News::detail'
        _arguments: {'news_title': 'news'}
    defaultController: 'News::list'
    defaults:
      page: '0'
    requirements:
      page: '\d+'
      news_title: '^[a-zA-Z0-9].*$'
    aspects:
      page:
        type: StaticRangeMapper
        start: '1'
        end: '100'
      news_title:
        type: PersistedAliasMapper
        tableName: 'tx_news_domain_model_news'
        routeFieldName: 'path_segment'

The problem

But I noticed that when I have multiple articles with the same title there's not a unique URL.

The question

How can I add the article uid to the path to make it unique or is that a good idea? I found that it was eluded to in the docs but don't know how to get it working to extend what I have already or if there's a better example someone can give me of how to get unique urls for news?

https://docs.typo3.org/typo3cms/extensions/core/latest/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html#persistedpatternmapper

Peter Kraume
  • 3,577
  • 2
  • 21
  • 39
god_is_love
  • 571
  • 5
  • 18
  • 2
    When you create a new article, with a title, which already exists in DB, then the URL Path Segment should already being generated in backend with a string appended by number. This is default TCA configuration (uniqueInSite). See EXT:news/Configuration/TCA/Overrides/tx_news_domain_model_news.php – jokumer Dec 07 '18 at 07:41

1 Answers1

5

The answer

routeEnhancers:
  NewsPlugin:
    type: Extbase
    extension: 'News'
    plugin: 'Pi1'
    routes:
      - { routePath: '/{news_title}', _controller: 'News::detail', _arguments: {'news_title': 'news'} }
    defaultController: 'News::list'
    aspects:
      news_title:
        type: PersistedPatternMapper
        tableName: 'tx_news_domain_model_news'
        routeFieldPattern: '^(?P<path_segment>.+)-(?P<uid>\d+)$'
        routeFieldResult: '{path_segment}-{uid}'