Routing exception after upgrading to TYPO3 v9.5.14 - typo3

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.

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 routeEnhancers for news archive (DateMenu) and pagination

With the below lines in the config.yaml, I configure the URLs for the news plugin in TYPO3. The URLs for the archive (year/month) look like expected, but don't work. I get an error 404.
/year/2020/07/
/year/2020/08/
and so on
When removing the two parts below the comments # Date year/month: and # Date year/month + pagination: I can see, that the archive links look like this:
/page-0/?tx_news_pi1[overwriteDemand][month]=08&tx_news_pi1[overwriteDemand][year]=2020&cHash=3f6c75083013c748da3870210647975b
/page-0/?tx_news_pi1[overwriteDemand][month]=07&tx_news_pi1[overwriteDemand][year]=2020&cHash=26bf541eb04daffaa9b43c033ea2bb90
and so on
The interestion part is the /page-0/ which shouldn't be there but comes from the paginator. After removing the page: '0' in the defaults section, the pagination isn't working anymore...
Am I missing something in my configuration?
My config.yaml:
base: '/'
baseVariants: { }
errorHandling: { }
languages:
-
title: Deutsch
enabled: true
base: /
typo3Language: de
locale: de_DE.UTF-8
iso-639-1: de
navigationTitle: ''
hreflang: ''
direction: ''
flag: de
languageId: '0'
rootPageId: 1
routeEnhancers:
PageTypeSuffix:
type: PageType
default: /
index: ''
map:
/: 0
#################################
########## News Plugin ##########
#################################
# see https://docs.typo3.org/p/georgringer/news/master/en-us/AdministratorManual/BestPractice/Routing/Index.html#human-readable-dates
NewsConfig:
type: Extbase
extension: News
plugin: Pi1
routes:
# Pagination:
- routePath: '/'
_controller: 'News::list'
- routePath: '/page-{page}'
_controller: 'News::list'
_arguments:
page: '#widget_0/currentPage'
requirements:
page: '\d+'
- routePath: '/{news-title}'
_controller: 'News::detail'
_arguments:
news-title: news
# Date year/month:
- routePath: '/year/{date-year}/{date-month}'
_controller: 'News::list'
_arguments:
date-month: 'overwriteDemand/month'
date-year: 'overwriteDemand/year'
page: '#widget_0/currentPage'
requirements:
date-month: '\d+'
date-year: '\d+'
# Date year/month + pagination:
- routePath: '/year/{date-year}/{date-month}/page-{page}'
_controller: 'News::list'
_arguments:
date-month: 'overwriteDemand/month'
date-year: 'overwriteDemand/year'
page: '#widget_0/currentPage'
requirements:
date-month: '\d+'
date-year: '\d+'
page: '\d+'
defaultController: 'News::list'
defaults:
page: '0'
date-month: ''
date-year: ''
aspects:
news-title:
type: PersistedPatternMapper
tableName: tx_news_domain_model_news
routeFieldPattern: '^(?P<path_segment>.+)-(?P<uid>\d+)$'
routeFieldResult: '{path_segment}-{uid}'
page:
type: StaticRangeMapper
start: '1'
end: '500'
date-month:
type: StaticRangeMapper
start: '1'
end: '12'
date-year:
type: StaticRangeMapper
start: '2000'
end: '2030'
routes: { }
UPDATE
With two different configurations I got it almost to work:
#####################################################
########## News detail page and pagination ##########
#####################################################
NewsGeneral:
type: Extbase
extension: News
plugin: Pi1
routes:
- routePath: '/{news-title}'
_controller: 'News::detail'
_arguments:
news-title: news
- routePath: '/page-{page}'
_controller: 'News::list'
_arguments:
page: '#widget_0/currentPage'
requirements:
page: '\d+'
defaultController: 'News::list'
defaults:
page: '1'
aspects:
news-title:
type: PersistedPatternMapper
tableName: tx_news_domain_model_news
routeFieldPattern: '^(?P<path_segment>.+)-(?P<uid>\d+)$'
routeFieldResult: '{path_segment}-{uid}'
page:
type: IdentifierValueMapper
#########################################
########## News archive config ##########
#########################################
# see https://docs.typo3.org/p/georgringer/news/master/en-us/AdministratorManual/BestPractice/Routing/Index.html#human-readable-dates
NewsArchiveConfig:
type: Extbase
extension: News
plugin: Pi1
limitToPages:
- 19
- 313
routes:
# Date year/month:
- routePath: '/year/{date-year}/{date-month}'
_controller: 'News::list'
_arguments:
date-month: 'overwriteDemand/month'
date-year: 'overwriteDemand/year'
# Date year/month + pagination:
- routePath: '/year/{date-year}/{date-month}/page-{page}'
_controller: 'News::list'
_arguments:
date-month: 'overwriteDemand/month'
date-year: 'overwriteDemand/year'
page: '#widget_0/currentPage'
requirements:
date-year: '\d+'
date-month: '\d+'
page: '\d+'
defaultController: 'News::list'
aspects:
date-month:
type: IdentifierValueMapper
date-year:
type: IdentifierValueMapper
page:
type: IdentifierValueMapper
Credits: The IdentifierValueMapperwas taken from here, thanks to exotec!
One last problem: The pagination on the archive pages.
The normal pagination link (/page-2/) leads to an error 404 and a month pagination (/year/2020/08/page-2/) does no respect the month and the year.
Conclusion:
If both configurations are active (which is the case on the archive page), they are interfering with each other.
Any hint is appreciated!

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

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

TYPO3 Route Enhancers: converting 'routeFieldName' to lowercase?

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