How do I get TYPO3 custom extension route to work? - typo3

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.

Related

form framework in news detail view

I tried to implement a form with form framework in the news detail view. The basic way is explained here:
https://docs.typo3.org/c/typo3/cms-form/10.4/en-us/I/Concepts/FrontendRendering/Index.html#render-within-your-own-extbase-extension
Viewhelper:
<formvh:render persistenceIdentifier="EXT:myext/Resources/Private/Forms/myforms.form.yaml"/>
Form definition:
renderingOptions:
controllerAction: detailAction
addQueryString: true
submitButtonLabel: Absenden
fluidAdditionalAttributes:
class: ''
identifier: myForm
label: 'myLabel'
type: Form
prototypeName: myPrototype
The form is displayed. When I submit the form the news detail view is shown again including the form, but it's empty. The form is not processed. Something is missing, but I cannot find it in the manual.
Thanks!
I think the important part is written in the note below the linked paragraph:
In general, you can override each and every form definition with the help of TypoScript (see ‘TypoScript overrides’). This feature is not supported when you are rendering forms via the RenderViewHelper.
Luckily, there is a solution for your problem: use the ‘overrideConfiguration’ parameter instead. This way, you can override the form definition within your template. Provide an according array as shown in the example below.
<formvh:render persistenceIdentifier="EXT:my_site_package/Resources/Private/Forms/MyForm.yaml" overrideConfiguration="{renderables: {0: {renderables: {0: {label: 'My shiny new label'}}}}}"/>
That means you can check for post-variables by TypoScript conditions and adjust the controllerAction (and view) accordingly. The show / detail action is not processing the form usually, so it's logical that another action has to be assigned. I'm not sure in the moment if it does matter if double opt-in or a confirmation page shall be shown, that might depend on the form-extension.
After some hours of experimenting i was able to solve the problem. It ist simply a matter of caching ...
Georg has implemented in news a special caching engine which ignores the config.no_cache = 1 definition in setup. So the detail view of news is always cached even when the whole installation ist set to config.no_cache = 1. So this combination seems to work:
Viewhelper in Detail.html:
<formvh:render persistenceIdentifier="EXT:myext/Resources/Private/Forms/myforms.form.yaml"/>
And this definitions in the yaml file of the form:
renderingOptions:
controllerAction: detail
addQueryString: true
submitButtonLabel: Absenden
additionalParams:
no_cache: 1
identifier: myForm
label: 'myLabel'
type: Form
prototypeName: myPrototype
This renders the whole page without cache which is not optimal. It would be better when only the news entry is rendered without cache. and there is the problem, that in many installations the parameter 'disableNoCacheParameter' is set in the localconfiguration file which disallowes no_cache=1 in urls.
So i looked for an other - better - possibility to work around this problem.
First make a new fluid template anywhere in your resources folder with the modified viewhelper from above:
<formvh:render persistenceIdentifier="{settings.persistenceIdentifier}"/>
Then write a typoscript like this:
lib.embeddedForm = COA_INT
lib.embeddedForm {
10 = FLUIDTEMPLATE
10 {
file = EXT:myext/Resources/Private/Forms/myForm.html
settings {
EXT:myext/Resources/Private/Forms/myforms.form.yaml
}
extbase {
pluginName = Formframework
controllerExtensionName = Form
controllerName = FormFrontend
controllerActionName = perform
}
}
}
And final you can embed the form with
<f:cObject typoscriptObjectPath="lib.embeddedForm" />
as COA_INT in the news template. This disables the caching of the form.
Perhaps it helps ...

Route Enhancer Configuration, when working with Extbase and Yoast

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

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.

TYPO3 Extension output altered by TYPO3?

TYPO3 seems to alter the output of my Frontend extension.
Simple Testcase:
function main($content, $conf)
{
$this->conf = $conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
return 'test';
}
When I call a page with this extension in the frontend i get:
test
Basically it prepends the path I used to access the page to the anchor link.
What could be responsible for this behaviour? RealURL?
How can I disable it?
You probably have somwhere in your TS template (in Setup) enabled prefixing:
config.prefixLocalAnchors = all
Note, that if you have set config.baseURL=http://some.tld/ and enabled RealURL this is required, otherwise all anchor links will be redirected to the main page:
http://some.tld/#test
instead of
http://some.tld/pagename/sub/other-sub#test