TYPO3 9 Routing - the parameter gets overwritten by the defaults - 1 year and 8 months later we are trying to update to TYPO3 10 and after that to TYPO3 11. As you can see, the site-configuration worked für typo3 9 perfectly, but now it won't anymore.
routeEnhancers:
Werbemittelshop:
type: Extbase
extension: Mwwerbemittelshop
plugin: Mwwerbemittelshop
routes:
-
routePath: '/{categoryname}/{categoryname2}/{categoryname3}'
_controller: 'MwWsCategories::category'
_arguments:
categoryname: mwWsCategory
categoryname2: mwWsCategory2
categoryname3: mwWsCategory3
-
routePath: '/{productname}'
_controller: 'MwWsCategories::product'
_arguments:
productname: mwWsProduct
defaults:
categoryname2: ''
categoryname3: ''
defaultController: 'MwWsCategories::category'
aspects:
categoryname:
type: PersistedAliasMapper
tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
routeFieldName: slug
categoryname2:
type: PersistedAliasMapper
tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
routeFieldName: slug
categoryname3:
type: PersistedAliasMapper
tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
routeFieldName: slug
productname:
type: PersistedAliasMapper
tableName: tx_mwwerbemittelshop_domain_model_mwwsproducts
routeFieldName: slug
The "productname" works exactly as expected. It is a readable url like example.de/test123 and it uses the right action of the controller.
"categoryname2" and "categoryname3" are the problems. If I open example.de/category1/ it works but if I add a second or a third parameter my parameters are empty (example.de/category1/category2) and I don't understand it.
/**
* action category
*
* #param \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory
* #param \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory2
* #param \MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory3
* #return void
*/
public function categoryAction(
\MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory = null,
\MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory2 = null,
\MwWerbemittelshop\Mwwerbemittelshop\Domain\Model\MwWsCategories $mwWsCategory3 = null
)
{
var_dump($this->request->getArguments());
var_dump($mwWsCategory);
exit;
Can somebody of you find my mistake? I tried so many versions of it and nothing worked. If you have questions or want some more code, just ask for it.
Thanks in advance.
I can't say why, but it's working if you define each case as own route:
one category
two categories
three categories
productsname
...and a default-case without any given parameters (or defaults!):
routeEnhancers:
Werbemittelshop:
type: Extbase
extension: Mwwerbemittelshop
plugin: Mwwerbemittelshop
routes:
-
routePath: '/{productname}'
_controller: 'MwWsCategories::product'
_arguments:
productname: mwWsProduct
-
routePath: '/{categoryname}'
_controller: 'MwWsCategories::category'
_arguments:
categoryname: mwWsCategory
-
routePath: '/{categoryname}/{categoryname2}'
_controller: 'MwWsCategories::category'
_arguments:
categoryname: mwWsCategory
categoryname2: mwWsCategory2
-
routePath: '/{categoryname}/{categoryname2}/{categoryname3}'
_controller: 'MwWsCategories::category'
_arguments:
categoryname: mwWsCategory
categoryname2: mwWsCategory2
categoryname3: mwWsCategory3
defaultController: 'MwWsCategories::category'
aspects:
categoryname:
type: PersistedAliasMapper
tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
routeFieldName: slug
categoryname2:
type: PersistedAliasMapper
tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
routeFieldName: slug
categoryname3:
type: PersistedAliasMapper
tableName: tx_mwwerbemittelshop_domain_model_mwwscategories
routeFieldName: slug
productname:
type: PersistedAliasMapper
tableName: tx_mwwerbemittelshop_domain_model_mwwsproducts
routeFieldName: slug
Related
Error message
(1/1) #1537298284 InvalidArgumentException
Enhancer type cannot be empty
I need to pass more than one argument to next page, how can I add more than more argument in config.yaml
This is my code:
FakteSemilivevideolist:
extension: FakteSemilivevideo
plugin: FakteSemilivevideo
routes:
-
routePath: '/{subuid}/{catuid}'
_controller: 'Videodetails::list'
_arguments:
subuid: subuid
catuid: catuid
defaultController: 'Videodetails::list'
defaults:
subuid: '0'
catuid: '0'
requirements:
subuid: '^[a-zA-Z0-9].*$'
catuid: '^[a-zA-Z0-9].*$'
aspects:
subuid:
type: PersistedAliasMapper
tableName: tx_faktesemilivevideo_domain_model_subcategory
routeFieldName: uid
catuid:
type: PersistedAliasMapper
tableName: tx_faktesemilivevideo_domain_model_category
routeFieldName: uid
in your configuration the type of RouteEnhancer is missing (e.g. type: Extbase). Also says the error message: "Enhancer type cannot be empty".
Your configuration must look like this:
FakteSemilivevideolist:
type: Extbase
extension: FakteSemilivevideo
plugin: FakteSemilivevideo
routes:
-
routePath: '/{subuid}/{catuid}'
_controller: 'Videodetails::list'
_arguments:
subuid: subuid
catuid: catuid
defaultController: 'Videodetails::list'
defaults:
subuid: '0'
catuid: '0'
requirements:
subuid: '^[a-zA-Z0-9].*$'
catuid: '^[a-zA-Z0-9].*$'
aspects:
subuid:
type: PersistedAliasMapper
tableName: tx_faktesemilivevideo_domain_model_subcategory
routeFieldName: uid
catuid:
type: PersistedAliasMapper
tableName: tx_faktesemilivevideo_domain_model_category
routeFieldName: uid
Kay
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.
Precondition
The ext:news list view plugin is on page www.domain.com/news [ID 9] and the detail view on www.domain.com/article [ID 39].
Following the official example (docs.typo3.org)
I tried the "Extbase Plugin Enhancer" example of the feature description, but that caused some problems:
The pagebrowser link to page 2 has a cHash: news/list/2?cHash=123456789
The pagebrowser link from page 2 to page 1 has lots of get-parameters: news?tx_news_pi1%5Baction%5D=list&tx_news_pi1%5Bcontroller%5D=News&cHash=123456789 . Without the routeEnhancer it would just be "news" without any get-parameters.
The link to the detail view has a cHash: article/blog/9?cHash=52e8a4b7c6318cfe0273e7eab374e9ae
The urls have unwanted segments ("list" + "blog")
The acticle url does not contain the news title
One cause for some of this issues might be that the paginator does not specify the controller in its links:
news?tx_news_pi1[#widget_0][currentPage]=2&cHash=123456789
My approach, which already fixes the mentioned problems
I splitted this to two separate routeEnhancers (Extbase + Plugin), removed the segments, "defaultController", "defaults", "requirements" and added "aspects":
routeEnhancers:
NewsDetail:
type: Extbase
limitToPages: [39]
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'
NewsList:
type: Plugin
limitToPages: [9]
routePath: '/{#widget_0/currentPage}'
namespace: 'tx_news_pi1'
aspects:
'#widget_0/currentPage':
type: StaticRangeMapper
start: '1'
end: '1000'
My concerns regarding this approach:
I'm unsure if it would have an advantage (performance or security) to add some "defaults" and "requirements" and if it really is good practice to split this into two separate routeEnhancers.
It limits the amount of list view pages to a maximum of 1000 (I admit that this is a lot). A higher value will result in an error: Range is larger than 1000 items.
If there's a slash / in the news title (f.e. "Monthly Report
2018/07") the automatically generated path_segment will also contain
a slash ("monthly-report-2018/07") and this leads to the following
error in the list view: Parameter "tx_news_pi1__news" for route
"tx_news_pi1_0" must match "[^/]++" ("monthly-report-2018/07" given)
to generate a corresponding URL.
Here is a copy of the YAML configuration created by Georg Ringer:
site_config.yaml
Version by Georg Ringer
rootPageId: 1
base: 'http://t3-master.vm/'
languages:
-
title: German
enabled: true
languageId: '0'
base: /
typo3Language: de
locale: de
iso-639-1: de
navigationTitle: DE
hreflang: ''
direction: ltr
flag: de
googleAnalyticsReportClientId: xxx
googleAnalyticsReportSiteId: yyyy
-
languageId: '1'
title: English
siteTitle: ''
navigationTitle: English
base: /en/
locale: en
iso-639-1: en
hreflang: en
direction: ''
typo3Language: default
flag: gb
fallbackType: strict
errorHandling: { }
baseVariants: { }
xxxx: "as\r\ndas\"\r\nas"
routes: { }
googleTagManager: ''
logo: ''
googleAnalyticsReportClientId: 778798369619-fl4nav20thdvfv2hag2lntf2cg1o2d79.apps.googleusercontent.com
googleAnalyticsReportSiteId: 'ga:136091502'
routeEnhancers:
NewsPlugin:
type: Extbase
limitToPages:
- 25
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'
-
routePath: '/time/{year}-{month}'
_controller: 'News::list'
_arguments:
year: overwriteDemand/year
month: overwriteDemand/month
-
routePath: '/category/{category}'
_controller: 'News::list'
_arguments:
category: overwriteDemand/categories
defaultController: 'News::list'
defaults:
page: '0'
year: ''
month: ''
requirements:
news_title: '^[a-zA-Z0-9].*$'
page: \d+
aspects:
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
page:
type: StaticRangeMapper
start: '1'
end: '100'
year:
type: StaticRangeMapper
start: '1970'
end: '2020'
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
category:
type: PersistedPatternMapper
tableName: sys_category
routeFieldPattern: '^(?P<title>.+)-(?P<uid>\d+)$'
routeFieldResult: '{title}-{uid}'
My Version
With the following Changes:
Added a trailing slash, to better match the old RealURL configuration
Additions for multilanguage
Removed ID from detail generation
Removed ID from category generation
Removed /page/ from the pagination example
Removed /time/ from the date example
Changed Year End from '2020' to '2099'
Overall structural improvements.
routeEnhancers:
PageTypeSuffix:
type: PageType
default: '/'
index: '/'
map:
'/': 0
NewsPlugin:
type: Extbase
extension: News
plugin: Pi1
limitToPages: [33,59]
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
localeMap:
- locale: 'de_.*'
map:
januar: '01'
februar: '02'
maerz: '03'
april: '04'
mai: '05'
juni: '06'
juli: '07'
august: '08'
september: '09'
oktober: 10
november: 11
dezember: 12
- locale: 'fr_.*'
map:
janvier: '01'
février: '02'
mars: '03'
avril: '04'
mai: '05'
juin: '06'
juillet: '07'
aout: '08'
septembre: '09'
octobre: 10
novembre: 11
décembre: 12
yes, you can have them both in the same routeEnhancer - without the unwanted segments:
routeEnhancers:
NewsPlugin:
type: Extbase
limitToPages:
- 9
- 39
extension: News
plugin: Pi1
routes:
-
routePath: '/{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'
aspects:
news_title:
type: PersistedAliasMapper
tableName: tx_news_domain_model_news
routeFieldName: path_segment
page:
type: StaticRangeMapper
start: '1'
end: '999'
That solved the problem fine (at the bottom): https://forge.typo3.org/issues/86895#note-9
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}'
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