Multiple controllers in an extension

2019-08-19 23:20发布

Is it actually possible to write an extension with multiple controllers that will work automatically on all sites? What i want is an extension that would call controller A when site A is opened, controller B when site B is opened and so on.

I saw here https://docs.typo3.org/typo3cms/extensions/news/ that multiple controllers is possible with FlexForms and switchableControllerActions. The thing is, when i add the plugin to the site, i have to specify which controller should work for this site. I want the configuration directly in the extension and not from typo3 backend.

I know i can use the page id and call the function based on it but i'm trying to avoid it and search for better solution.

1条回答
神经病院院长
2楼-- · 2019-08-19 23:42

Sure this is possible. You need to use FlexForms here which is basically XML based field in your tt_content record. Thus you can configer your plugin directly your content record. Typically used for setting limit to records, sorting, etc. But also for setting any allowed controller->action combination, where the first one is default. Just have a look at some of the well know extensions how they use it. Here is a little abstract fore the relavant part of the FlexForm:

                    <switchableControllerActions>
                    <TCEforms>
                        <label>LLL:EXT:ra_registration/Resources/Private/Language/locallang_be.xml:flexforms_general.mode</label>
                        <config>
                            <type>select</type>
                            <items>
                                <numIndex index="0">
                                    <numIndex index="0">LLL:EXT:ra_registration/Resources/Private/Language/locallang_be.xml:flexforms_general.mode.registration_index</numIndex>
                                    <numIndex index="1">Registration->index;Registration->register;User->new;User->create;User->confirm;User->index;User->remind</numIndex>
                                </numIndex>
                                <numIndex index="1">
                                    <numIndex index="0">LLL:EXT:ra_registration/Resources/Private/Language/locallang_be.xml:flexforms_general.mode.registration_reminder</numIndex>
                                    <numIndex index="1">User->index;User->remind;User->remindConfirm</numIndex>
                                </numIndex>
                            </items>
                        </config>
                    </TCEforms>
                </switchableControllerActions>

As said you can define any controller / action combination such as MyProduct->index or MyCustomer->list etc.

In order use the FlexForm you need to register it in the ext_tables.php

$TCA['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue('myextenion_pi1', 'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForms/setup.xml');
查看更多
登录 后发表回答