TYPO3 Route Enhancers: converting 'routeFieldName' to lowercase? - typo3

Intro: In TYPO3 v9 you're able to set up speaking URLs out-of-the-box without using the RealURL extension. This feature is configured with YAML in a so-called Site Configuration.
The following configuration excerpt extends the speaking URLs for the popular news extension. Below config category_name and tag_name I select the title field in the corresponding database tables.
Q: Is it possible to convert these titles to lowercase letters? The current configuration results in URLs like domain.com/category/TYPO3.
routeEnhancers:
NewsPlugin:
type: Extbase
limitToPages: [17,4]
extension: News
plugin: Pi1
routes:
# Detail view:
- routePath: '/{news_title}'
_controller: 'News::detail'
_arguments: {'news_title': 'news'}
# Categories:
- routePath: '/{category_name}'
_controller: 'News::list'
_arguments: {'category_name': 'overwriteDemand/categories'}
# Tags:
- routePath: '/{tag_name}'
_controller: 'News::list'
_arguments: {'tag_name': 'overwriteDemand/tags'}
defaultController: 'News::list'
aspects:
news_title:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_news'
routeFieldName: 'path_segment'
category_name:
type: PersistedAliasMapper
tableName: 'sys_category'
routeFieldName: 'title'
tag_name:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_tag'
routeFieldName: 'title'

It is easy. You can do it as made it in the ext: news
I did it the same for category and tag and it is all working good.
Look at attachment:
More about it here

Related

TYPO3 News routing not working properly. But its working in the URL showing in Sitemap

Following is my config.yaml configuration to make the detail page URL user friendly.
News:
type: Extbase
limitToPages:
- 23
extension: News
plugin: Pi1
routes:
-
routePath: '{news_title}'
_controller: 'News::detail'
_arguments:
news_title: news
-
routePath: '/topic/{category_name}'
_controller: 'News::list'
_arguments:
category_name: overwriteDemand/categories
defaultController: 'News::list'
defaults:
page: '0'
requirements:
news_title: '^[a-zA-Z0-9].*$'
page: \d+
aspects:
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
category_name:
type: PersistedAliasMapper
tableName: sys_category
routeFieldName: path_segment
NewsList:
type: Plugin
routePath: '/browse/{#widget_0/currentPage}'
namespace: tx_news_pi1
aspects:
'#widget_0/currentPage':
type: StaticRangeMapper
start: '1'
end: '1000'
I need a URL like: https://www.example.com/article/lorem-ipsum-dolor
But the obtained URL is: https://www.example.com/article/?tx_news_pi1%5Bnews%5D=1&cHash=0bfd8bb6d92152b35569116fa86a2406
The same code is used in other projects too It is perfectly working there.
But in my sitemap.xml I can see the correct URL There.
Can anyone help me? Why the URL is correct only in the sitemap.
Thank you.
I found the problem.
link {
skipControllerAndAction = 1
}
There is a skipControllerandAction in my news setup. I have removed this and now it working well.
Thanks!!
The above solution (from the previous answer) works in me -
remove/comment the skipControllerAndAction:
link {
#skipControllerAndAction = 1
}

Typo3 9 Routing config generating 404 error

We have a Typo3 9 server with a number of websites running on it. We also have the news plugin to facilitate the addition of blog posts.
With Typo3 9 the old RealURL system has been depricated in favour of a built in system. This is working for the normal pages but is not working for the news articles.
We have implemented the following YAML confic file which is based off the examples provided by the news plugin and a number of other stack overflow posts. The problem is that while we can confirm that the config is loaded, we get a 404 error:
404 Page not found!
Reason: The requested page does not exist
Current URL: /blog/2020-january/
We then commenced in depth, line by line examinantion of the code to understand what is going wrong. We did manage to render the /blog/2020-january/ page, but it had no content. None of the individual blog pages resolve either.
Are there other configurations that we should look for to enable this functionality? We have had another Typo3 person look at the problem without success.
rootPageId: 156
base: 'https://example.site'
baseVariants: { }
languages:
-
title: English
enabled: true
languageId: '0'
base: /
typo3Language: default
locale: en_AU
iso-639-1: en
navigationTitle: ''
hreflang: ''
direction: ''
flag: au
errorHandling: { }
routes: { }
routeEnhancers:
PageTypeSuffix:
type: PageType
default: '/'
index: '/'
map:
'/': 0
NewsPlugin:
type: Extbase
extension: News
plugin: Pi1
limitToPages:
- 187
- 201
routes:
# Detail view:
- routePath: '/{news_title}'
_controller: 'News::detail'
_arguments: {'news_title': 'news'}
# Categories:
- routePath: '/{category}'
_controller: 'News::list'
_arguments: {'category': 'overwriteDemand/categories'}
# Tags:
- routePath: '/{tag_name}'
_controller: 'News::list'
_arguments: {'tag_name': 'overwriteDemand/tags'}
# Pagination:
- routePath: '/{page}'
_controller: 'News::list'
_arguments: {'page': '#widget_0/currentPage'}
# Archive:
- routePath: '/{localized_archive}/{year}/{month}'
_controller: 'News::archive'
# Date:
- routePath: '/{year}-{month}'
_controller: 'News::list'
_arguments:
year: overwriteDemand/year
month: overwriteDemand/month
defaultController: 'News::list'
defaults:
page: '0'
year: ''
month: ''
requirements:
page: '\d+'
news_title: '^[a-zA-Z0-9].*$'
aspects:
page:
type: StaticRangeMapper
start: '1'
end: '100'
news_title:
type: PersistedPatternMapper
tableName: tx_news_domain_model_news
routeFieldPattern: '^(?P<path_segment>.+)$'
routeFieldResult: '{path_segment}'
category:
type: PersistedAliasMapper
tableName: 'sys_category'
routeFieldName: 'title'
tag_name:
type: PersistedAliasMapper
tableName: 'tx_news_domain_model_tag'
routeFieldName: 'title'
localized_archive:
type: LocaleModifier
default: 'archive'
routeFieldName: 'title'
localeMap:
- languageId: 'de_.*'
value: 'archiv'
- languageId: 'fr_.*'
value: 'archives'
year:
type: StaticRangeMapper
start: '1970'
end: '2099'
month:
type: StaticValueMapper
map:
january: '01'
february: '02'
march: '03'
april: '04'
may: '05'
june: '06'
july: '07'
august: '08'
september: '09'
october: 10
november: 11
december: 12
Please check your code see below code of news_title
routeEnhancers: News: type: Extbase extension: News plugin: Pi1 routes: - routePath: '/{news-title}' _controller: 'News::detail' _arguments: news-title: news aspects: news-title: type: PersistedAliasMapper tableName: tx_news_domain_model_news routeFieldName: path_segment
Remove curly braces from path_segment, remove do it as above or in docs thank you
Please see the official documents https://docs.typo3.org/p/georgringer/news/7.2/en-us/AdministratorManual/BestPractice/Routing/Index.html
After a lot of effort we have success.
Firstly, the final working config:
routeEnhancers:
NewsPlugin:
type: Extbase
extension: News
plugin: Pi1
limitToPages:
- 201
- 187
routes:
-
routePath: '/{news_title}'
_controller: 'News::detail'
_arguments:
news_title: news
-
routePath: '/{category}'
_controller: 'News::list'
_arguments:
category: overwriteDemand/categories
-
routePath: '/{tag_name}'
_controller: 'News::list'
_arguments:
tag_name: overwriteDemand/tags
-
routePath: '/page-{page}'
_controller: 'News::list'
_arguments:
page: '#widget_0/currentPage'
-
routePath: '/{year}/{month}'
_controller: 'News::list'
_arguments:
year: overwriteDemand/year
month: overwriteDemand/month
defaultController: 'News::list'
# defaults:
# page: '0'
# year: ''
# month: ''
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
category:
type: PersistedAliasMapper
tableName: sys_category
routeFieldName: title
tag_name:
type: PersistedAliasMapper
tableName: tx_news_domain_model_tag
routeFieldName: title
year:
type: StaticRangeMapper
start: '1970'
end: '2099'
month:
type: StaticRangeMapper
start: '01'
end: '12'
#month:
# type: StaticValueMapper
# map:
# january: '01'
# february: '02'
# march: '03'
# april: '04'
# may: '05'
# june: '06'
# july: '07'
# august: '08'
# september: '09'
# october: 10
# november: 11
# december: 12
The important things:
The pagination path includes the page prefix. There is no ambiguity about what page it is on.
No trailing slashes, additionally, the articles also can't have trailing slashes in the path segment. This can be done in the database and clearing the cache after
No defaults
The different month mapping is due to a requirement to match an existing system
We upgraded from 9.5.15 to 9.5.18. It is not clear if this was required.
In the site package, the default TypoScript template included link.skipControllerAndAction = 1. This needs to be removed to show the friendly urls for the articles in the list view. (See How to properly set url-routing for tx-news in TYPO3 9.5.5?)
Finally, for the date, tag and category filters to work, Disable override demand in List->Plugin->Additional must be unticked.

How to get Speaking URLs for News on Typo3 9.5

How to migrate from realurl in TYPO3 9.5 ?
I have a list view where you can filter by category AND year.
Filter by category only and filter by year only works, but I it doesnt work for a combined filter as with realurl before. (first route see below)
my current url is: events?tx_news_pi1[overwriteDemand][categories]=34&tx_news_pi1[overwriteDemand][year]=2019
my desired url: events/2019/categoryname
routeEnhancers:
News:
type: Extbase
extension: News
plugin: Pi1
limitToPages:
# list and detail page
- 6
- 42
routes:
# this doesn't work for events?tx_news_pi1[overwriteDemand][categories]=34&tx_news_pi1[overwriteDemand][year]=2019
# with realurl the path was: events/2019/categoryname
- routePath: '/{date-year}/{category-name}'
_controller: 'News::list'
_arguments:
category-name: overwriteDemand/categories
date-year: overwriteDemand/year
requirements:
date-year: '\d+'
defaultController: 'News::list'
defaults:
date-year: ''
aspects:
date-year:
type: StaticRangeMapper
start: '2000'
end: '2030'
category-name:
type: PersistedAliasMapper
tableName: sys_category
routeFieldName: slug

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
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
https://symfony.com/doc/4.3/routing.html#optional-parameters
https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.5.x/Important-86895-RouteAspectsTakePrecedenceOverRequirements.html
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
First off, consider https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.5.x/Important-86895-RouteAspectsTakePrecedenceOverRequirements.html
The culprit is the default configuration for the page aspect.
It was once introduced to make sure that the URL for the first tag page is always "/tag-name" and only subsequent pages have "/tag-name/page/2" and so on.
This default value now needs to be removed in order to have the requirements applied as desired.

TYPO3 9.5 LTS routeEnhancers for news with uid to make path unique

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
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}'