Route Enhancer Configuration, when working with Extbase and Yoast - typo3

Since I have created a route enhancer for single view entries of one of our typo3 extensions, the title and description fields are no longer being processed to the frontend. <title></title> consists only of the page title instead of the record title and <meta name="description" .../> is missing completely. If I remove the route enhancer SeminarSingleView, the links are ugly again, but the tags are filled correctly.
Typo3 9.5.14
Yoast 6.0.1
Here is the part from the config.yaml that deals with route enhancing:
routeEnhancers:
PageTypeSuffix:
type: PageType
default : ''
map:
sitemap.xml: 1533906435
yoast-snippetpreview.json: 1480321830
SeminarSingleView:
type: Extbase
limitToPages: [62,142]
namespace: the_namespace
routes:
- { routePath: '/{url_slug}', _controller: 'Product::show', _arguments: {'url_slug' : 'product'} }
defaultController: 'Product::show'
aspects:
url_slug:
type: PersistedAliasMapper
tableName: 'the_table'
routeFieldName: 'speaking_url'
The route enhancer itself works like a charm. Is there anything missing that I do not see? I've read through these two:
https://wiki.sebkln.de/doku.php?id=typo3:yoast_seo
https://docs.typo3.org/p/yoast-seo-for-typo3/yoast_seo/6.0/en-us/Index.html
but could not find information that struck me as useful. Any ideas? I can and will obviously provide more information if needed. The line yoast-snippetpreview.json: 1480321830 is new and was part of my
attempt to fix the problem. But it only fixed the preview in the backend. A problem no one had realized yet existed.

We were able to fix the problem at long last.
The culprit was some deprecated Typoscript in the extension's setup.ts, so the problem did hinge on the update from 8.7.x to 9.5.x.
[globalVar = GP:tx_extension_tablename|field > 0]
had to be replaced with
[request.getQueryParams()['tx_extension_tablename']['field'] > 0]
The change itself is documented here: https://www.nitsan.in/blog/all-you-need-to-know-about-typoscript-conditions-with-symfony-expression-language/#c2419

Related

How do I get TYPO3 custom extension route to work?

Perhaps am missing something. I've searched and found answers such as this. For me, the whole thing doesn't work.
So my pages load via TypoScript (as one might expect):
# PAGE
# **********************
page=PAGE
page{
typeNum=0
shortcutIcon=favicon.ico
10=USER
10{
userFunc=TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName=Shop
pluginName=Main
}
}
I have a couple of pages (1 and 2) and they all work fine. Page 1 is root page.
Then I have routes that look like this:
routeEnhancers:
Account:
type: Extbase
limitToPages:
- 1
extension: Shop
plugin: Account
routes:
- routePath: /a
_controller: 'Account::accountLogin'
- routePath: /a/r
_controller: 'Account::accountRegistration'
My plugin registration in ext_localconf.php looks like this:
/**
* Plugins
*/
(static function(){
ExtensionUtility::configurePlugin('shop', 'Page', [PageController::class=>'main']);
ExtensionUtility::configurePlugin('shop', 'Account', [AccountController::class=>'accountLogin,accountRegistration']);
})();
When I try to access the root page https://127.0.0.1/ it works fine. When I access a subpage (page 2) of page 1, everything works fine as well. But when I try to access https://127.0.0.1/a, the request never hits the accountLogin action of the AccountController. Neither does https://127.0.0.1/a/r. So I checked under the hood and found that The PageResolver middleware does indeed single out the correct routePath from the list of available paths. The controller and action of the route is then carried in a PageArguments object. All looks good but it never gets to the accountLogin action. It's totally ignored in the process.
Previously with earlier versions it worked fine.
What could I be doing wrong? or did some change take place with the new version?
Using version 11.5.8
Apparently the TypoScript carrying the plugin for the AccountController was not loaded.

TYPO3 routing: every route has to be unique within a plugin?

It seems that every "routePath" has to be unique within the same plugin, even for different actions, which is a design fault or bug in my eyes.
Example with EXT:news, which has plugin "Pi1" with actions "list" and "detail", using default setup (https://docs.typo3.org/p/georgringer/news/8.6/en-us/AdministratorManual/BestPractice/Routing/Index.html#basic-setup-including-categories-tags-and-the-rss-atom-feed). When having the same slug for a news record and a news category record (e.g. "hello-world") you are getting a problem, the route "news/list/hello-world" doesn't list the news of category "hello world" because "hello world" is recognized as news title (just because it's configured before the category in the site configuration).
What to do in this case? Using configuration option "limitToPages" (what is not ideal when having editors adding new plugins)? Splitting it up in different plugins (what is not possible for third party extensions)? Prefixing routePath, e.g. "category-*" (what also doesn't help when an editor creates a news with this slug)?
No, sorry to say that this is not a design fault, it is a configuration fault or an data conflict.
Neither a human nor a machine/program could determine if you now mean with a
valid part of a url having two or multiple routes, which checks further data and both has has a valid value for it, thus both are matching and are "valid" routes.
But as there can only one route be executed, you could either implemend or say do the first, or the last of it, which is done (not sure which one currently).
So, your route configuration is not deterministic at all. You can shift the order of both routes to change which one will win if both are considiered valid and matched.
So you have following options to be more deterministic:
seperate list and detail on different pages and have the distinction that way
use a prefix path for the detail routePath
prefix the routePaths for the category and/or tag name routePaths
Maybe it would be better to ship that as example or in the documentation for the news extionsion. But as there a lot of different use cases and constellations, there could only be examples. They have to be correctly setup for that instance, and project needs. (This does apply to all plugins, not only ext:news.)
routeEnhancers:
News:
type: Extbase
extension: News
plugin: Pi1
routes:
- routePath: '/'
_controller: 'News::list'
- routePath: '/page-{page}'
_controller: 'News::list'
_arguments:
page: '#widget_0/currentPage'
# detail subroute prefixed
- routePath: '/detail/{news-title}'
_controller: 'News::detail'
_arguments:
news-title: news
# list category subroute prefixed
- routePath: '/category/{category-name}'
_controller: 'News::list'
_arguments:
category-name: overwriteDemand/categories
# list tag subroute prefixed
- routePath: '/tag/{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
PageTypeSuffix:
type: PageType
map:
'feed.xml': 9818

TYPO3: How to access GET/POST parameters of a slug url within typoscript?

I have a small extension with a custom content element.
Having a list and detail view.
Before i configured the route enhancers i had a url like this.
https://www.domain.de/index.php?id=9&tx_gfseminare_[uid]=1&tx_gfseminare_[action]=show&tx_gfseminare_[controller]=Standard
Here i could access the url parameters easily with
data = GP:tx_gfseminare_|uid
After the setup of the routeenhancer the url looks like following.
https://www.domain.de/personal-coaching/workshops/ipsum-dolor-sit-amet-consectetuer-adipiscing-elit-1
routeEnhancers:
GfSeminare:
type: Extbase
extension: GfSeminare
plugin: ''
routes:
- routePath: '{titel}'
_controller: 'Standard::show'
_arguments:
titel: 'seminar'
aspects:
titel:
type: PersistedAliasMapper
tableName: 'tx_gfseminare_kurse'
routeFieldName: 'tx_gfseminare_slug'
But i can not access the url-parameters anymore.
How can i access GET/POST-Parameters within typoscript?
Thanks in advance
Niels
UPDATE:
I tried following with no result:
GP:tx_myext_uid,GP:tx_myext_[uid],GP:tx_myext_seminar,GP:tx_myext_[seminar],GP:tx_myext_|seminar,GP:tx_myext_|[seminar],GP:tx_myext_|uid,GP:tx_myext|uid,GP:tx_myext|seminar. Also combination with or without tx_ and so on. I never get any output
UPDATE (27.01.2020):
If i set plugin: Show in the route enhancer i get an output if i browse a old beautified url like https://mydomain.de/personal-coaching/workshops/ipsum-dolor-sit-amet-consectetuer-adipiscing-elit-1 with GP:tx_gfseminare_|seminar.
But now the urls get not beautified! I get normal URLs with parameters https://mydomain.de/personal-coaching/workshops?tx_gfseminare_%5Baction%5D=show&tx_gfseminare_%5Bcontroller%5D=Standard&tx_gfseminare_%5Bseminar%5D=3&cHash=9fd0c7039c8cfc3bf14da57f45791fdb
In summary:
With "plugin: Show" -> result(browse an old beautified url) but no beautified urls anymore (normal parameters appended at url)
With "plugin: ''" -> beautified urls but no result anymore
Also tried plugin: Pi1 with no result.
I´m totally frustrated because with TYPO3 8.x this was a 5 minute thing. Now i tried many many hours with no result for such an easy thing.
Also the manual describe many variants but no variant with an easy content element (where i have an reduced extension configuration). Maybe this is the problem. I don´t know. ATM i deactivated the route enhancer, have url with parameters but it works.
Hopefully anyone has an idea which works.
With your config, the uid will be in the GET-variable 'tx_myext_[seminar]'.
I have tested this just for fun and I can access the GET parameters pretty easy from my custom extension in TYPO3 9.5.11 with this example code in the setup:
page.80 = TEXT
page.80.data = gp:tx_eventlist_show|event
page.90 = TEXT
page.90.data = gp:tx_eventlist_show|action
// Output for 'https://panama-traveller.com/events/show/panama-jazz-festival-5':
// 5 show
And here's my route enhancer setup:
EventsShowPlugin:
type: Extbase
extension: Eventlist
plugin: Show
routes:
-
routePath: '/{event_title}'
_controller: 'Event::show'
_arguments:
event_title: event
defaultController: 'Event::list'
defaults:
page: '0'
requirements:
page: '\d+'
event_title: '^[a-zA-Z0-9].*$'
aspects:
event_title:
type: PersistedPatternMapper
tableName: tx_eventlist_domain_model_event
routeFieldPattern: '^(?P<slug>.+)-(?P<uid>\d+)$'
routeFieldResult: '{slug}-{uid}'

How to translate the URL with router enhancer

I have a customized extbase extension, which shows different contents based on the parameter.
class SiteController extends ActionController {
/**
* #param int $year
*/
protected function newsAction(int $year) {
......
}
}
And here is my routeEnhancers in the config.yaml.
routeEnhancers:
News:
type: Extbase
limitToPages: [6]
extension: Site
plugin: Pi1
routes:
- routePath: '/{year}',
_controller: 'Site:news'
However, it doesn't convert the URL http://landing.io/news?tx_site_pi1[year]=2018&cHash=f1a79b262f6567570dd78b6148b17554 to http://landing.io/news/2018, but I can visit http://landing.io/news/2018?cHash=f1a79b262f6567570dd78b6148b17554. So, I guess I missed something.
Could anyone help?
First of all, fix a typo in the config.yaml, it should be Site::news instead of Site:news.
After some debug, I finally solved this question.
According to the Routing Enhancers and Aspects, it's said
When creating extbase plugins, it is very common to have multiple controller/action combinations. The Extbase Plugin Enhancer is therefore an extension to the regular Plugin Enhancer, providing the functionality that multiple variants are generated, typically built on the amount of controller/action pairs.
in the Extbase Plugin Enhancer section.
However, if you want to have the extbase routing enhancers to work, you MUST have &tx_ext_pi1[controller]=CONTROLLER&tx_ext_pi1[action]=ACTION in your URLs, which is all the URLs do in the section but I didn't realize. Otherwise, you will get FALSE in \TYPO3\CMS\Extbase\Routing\ExtbasePluginEnhancer::verifyRequiredParameters() and never get your URLs translated. So, I think this point should be included in the doc, or at least highlight the last sentence starting from "typically".
Meanwhile, there is also a TypoScript setting in the EXT:extbase, called config.tx_extbase.features.skipDefaultArguments or plugin.tx_ext.features.skipDefaultArguments, which will remove the controller and/or action arguments if they are equal to the default controller/action of the target plugin. If it's enabled, it will also break the routing enhancers for the same reason. Unfortunately, I enabled this since very beginning to make the URLs short.
There is another setting, config.tx_extbase.mvc.callDefaultActionIfActionCantBeResolved, you may need to be care about, which might cause the same problem.
Anyway, the new routing feature is pretty great.

GPVar condition is not working when parameter is "slugified" in TYPO3 9LTS

In TypoScript it's possible to use conditions, e.g. to detect if a single view of a news should be shown. This looks like
[globalVar = GP:tx_news_pi1|news > 0]
or the like. This construct does not work anymore in 9LTS (9.5.7), if the named parameter is "slugified" in the site configuration like
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
Without the given configuration the condition works well.
I expect the GPvar condition will be valid, even the parameter is not in the URL because of the mapping. At least I expect another condition to achieve the detection if a parameter is set, even if it's mapped to a slug/path_segment
Found it: Symfony expressions are working:
[(request.getQueryParams()['tx_news_pi1'])['news'] > 0 || (request.getParsedBody()['tx_news_pi1'])['news'] > 0]