How to translate the URL with router enhancer - typo3

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.

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 8, Form extension - best practice for custom yaml files

When generating forms with the form module the corresponding yaml files get stored in fileadmin/user_upload.
Now I want to integrate those yaml files into my sitepackage and thus into my CVS. Where is the correct place for them? In the example extension they are stored in Resources/... while I would think they have to go into Configuration/Yaml
And how do I configure the form extension to search them in that place?
While it's basically a matter of taste where exactly one saves his form definitions, I try to separate form configuration and form definitions.
From the official documentation:
[...] the form configuration allows you to define:
which form elements, finishers, and validators are available,
how those objects are pre-configured,
how those objects will be displayed within the frontend and backend.
In contrast, the form definition describes the specific form,
including
all form elements and their corresponding validators,
the order of the form elements within the form, and
the finishers which are fired as soon as the form has been submitted.
Furthermore, it defines the concrete values of each property of the mentioned aspects.
So, for more clarity I save all form configuration in a sitepackage under Configuration/Yaml/ and the form definitions under Resources/Private/Forms, neighbouring the templates.
I wrote a full tutorial how to use custom templates with EXT:form, which also includes the answers to your question.
In short:
Register YAML configuration with TypoScript in your extension root folder as ext_typoscript_setup.txt (as recommended1)
plugin.tx_form.settings.yamlConfigurations {
100 = EXT:my_extension/Configuration/Yaml/CustomFormSetup.yaml
}
module.tx_form.settings.yamlConfigurations {
100 = EXT:my_extension/Configuration/Yaml/CustomFormSetup.yaml
}
CustomFormSetup.yaml – setting up a new storage path
TYPO3:
CMS:
Form:
persistenceManager:
allowedExtensionPaths:
10: EXT:my_extension/Resources/Private/Forms/
allowSaveToExtensionPaths: true
allowDeleteFromExtensionPaths: true
1TypoScript inside an ext_typoscript_setup.txt is automatically loaded in both frontend and backend of your TYPO3 installation directly after installing your extension. This differs from other TypoScript files, which have to be included manually, e.g. as static templates. See official Form Framework documentation.
I'd suggest Resources/Private/Forms for your form definitions. The form extension clarifies how to register additional form definition paths.

TYPO3 Extbase: Set storagepid for Backend Module

I have written a small extension that provide news for Backend User.
Ist is just 2 Parts. One part showing the news for all BE User as a own Module, and the other part are create and edit functions provided by the TCA.
To work with the TCA forms and the default extbase getter, i need the correct storagePid. I can't set them via TypoScript, because I'm never in a page context.
My Idea was to use the Plugin settings with the file ext_conf_template.txt
# cat=persistence/enable; type=int; label=Storage pid
storagePid = 4457
But how can I tell TYPO3 to look at this Settings?
At least Repository->findAll() must respect it
Normally you would define this using TypoScript:
module.tx_yourextensionkey.persistence.storagePid = 123
Not being in a page context is not a blocker as long as you place the configuration on the first root TypoScript template (or include the TypoScript via other means which cause global inclusion not specific to any sys_template record or page tree location).
Maybe not the best solution, but it works.
I have written my own function in the repository with the pid as parameter.
I'm using the TYPO3 Query builder.
With $query->equals('pid', $pid); I get entries with my pid.
And with $query->getQuerySettings()->setRespectStoragePage(false); the default pid will be ignored.
And as the last step. My Controller gets the pid from the Settings, unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['my_extension']['storagePid']); an gives it to the function.

Manage hierarchy / enforce priority of TS-templates

Well, there is actually another guy with exact the same problem. But until today, they didn't come up with a solution, that's why I'm asking it once again.
My entire TS is included by an extension in TYPO3 7.6.8. This works fine except with indexed_search. The TS inside my resources EXT get overwritten by the indexed_search default TS.
This is the order of the TS inside the Template-Analyzer:
SYS: TYPO3_CONF_VARS:FE:defaultTypoScript
EXT:fluid_styled_content/Configuration/TypoScript/...
... a bunch of other third party extensions ...
EXT:indexed_search/Configuration/TypoScript
EXT:templates_ext/Resources/Private/TypoScript
extbase
fluid
extensionmanager
belog
beuser
felogin
indexed_search
sys_note
realurl
So #7 is the extension which includes all my TS but it gets overwritten by #14. The only way to configure the indexed_search is inside the setup of the page template (which comes after all those above). But I want to avoid that to keep things clean.
Is there a way to prioritize a certain TS so that it doesn't get overwritten?
Open the TypoScript record, switch to the tab "Includes", at the bottom you will find the field Static Template Files from TYPO3 Extensions:. Select the value Include before all static templates if root flag is set.
Try putting the TS from your template extension inside the root page Setup field like this (adjust the path if necessary, your example says Resources/Private/TypoScript?):
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:templates_ext/Configuration/TypoScript/setup.ts">
This should make sure that it is included AFTER all the other includes (I assume you included those via the includes tab?)

Symfony router with translated urls

I trying to build an router in Symfony with annotation where also the urls are translated. I would like to have all the following urls routed to the same controller:
/over-ons
/nl/over-ons
/en/about-us
I use the following annotation router:
/**
* #Route("/{_locale}/over-ons", defaults={"_locale": "nl|en"}, requirements={"_locale": "nl"}, name="about-us")
* #Route("/{_locale}/about-us", defaults={"_locale": "nl|en"}, requirements={"_locale": "en"}, name="about-us")
*/
But when I generate via path an url in Twig always the last #route is used instead of the one of the correct set _locate. Any advice would be helpful?
Would it also by wise from SEO poiunt of view to support .html behinde the urls?
If you're adding those 2 annotations on the same controller method, then of course only the last one is used because it overrides all the previous ones.
If you want good and solid internationalization support, I recommend using JMSI18nRoutingBundle.