I don't know if I've set up my extension a little quirky.
I have one model, but two plugins, as I would like to display the same data in different ways.
What thought I'd do: assign pi1 and pi2 two different Fluid templates, where all the display logic is done. But as far as I understood now, there is no such switch, due to "Convention over configuration", I need a separate controller for pi2, right?
Now I have this in ext_tables.php:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'STUBR.' . $_EXTKEY,
'Pi1',
array(
'Institution' => 'list, show',
),
// non-cacheable actions
array(
'Institution' => '',
)
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'STUBR.' . $_EXTKEY,
'Pi2',
array(
'Institution' => 'list, show',
),
// non-cacheable actions
array(
'Institution' => '',
)
);
Do I really have to adapt everything by re-naming "Institution" here, in the Controller(s) and in the template directories?
To answer the question you asked in your answer ... it is possible to configure the TypoScript of your Extension on a per plugin base. Just add the pluginname with a leading underscore to your TS key like this
plugin.tx_stellen_pi2 {
settings {
displaymode = 1
}
}
Instead of using a if condition you could also set a different TemplateRootPath so another template would be rendered for pi2.
Remember that you can set the displayMode in a FlexForm. Every FlexForm property prefixed with settings. will be available in the {settings} array. Just configure the FlexForm in ext_tables.php:
$pluginSignature = str_replace('_','',$_EXTKEY) . '_pi1';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForm/flexform_pi1.xml');
Then add the FlexForm XML to the path configured:
<T3DataStructure>
<meta>
<langDisable>1</langDisable>
</meta>
<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>Configuration</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.displayMode>
<TCEforms>
<exclude>0</exclude>
<label>Display mode</label>
<config>
<type>select</type>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0">Neat</numIndex>
<numIndex index="1">1</numIndex>
</numIndex>
<numIndex index="1" type="array">
<numIndex index="0">Clean</numIndex>
<numIndex index="1">2</numIndex>
</numIndex>
</items>
<minitems>0</minitems>
<maxitems>1</maxitems>
<size>1</size>
</config>
</TCEforms>
</settings.displayMode>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
In this example, a select box with two options "neat" and "clean" is added.
You can then use this in your Fluid template (you could also use the SwitchViewHelper instead of the if construct if you have more than two modes):
<f:if condition="{settings.displayMode} == 1">
<f:then>
<f:render partial="Neat/List" arguments="{_all}" />
</f:then>
<f:else>
<f:render partial="Clean/List" arguments="{_all}" />
</f:else
</f:if>
Remember that you can nest partials, so it's no problem to have a partial in a partial in a partial. So just use a partial for each view.
If you want to have it less hackish-looking, you could give the display mode a speaking value:
<numIndex index="0" type="array">
<numIndex index="0">Neat</numIndex>
<numIndex index="1">Neat</numIndex>
</numIndex>
<numIndex index="1" type="array">
<numIndex index="0">Clean</numIndex>
<numIndex index="1">Clean</numIndex>
</numIndex>
Then you can use this to call the partial like this
<f:render partial="List/{settings.displayMode}" arguments="{_all}" />
and get rid of the if construct that way.
I'm doing it this way now. Keep one controller, just fork the template by setting some page TS on the page the plugin is on.
plugin.tx_stellen {
settings {
displaymode = 1
}
}
and then <f:if condition="{settings.displaymode}==1"></f:if>
This is workaroundish, though, as it is valid for the entire page (and I wouldn't even need the three different plugins at all). Isn't it possible to define TypoScript "per Plugin" directly in the extension?
Related
What if two different methods of an extension need to be called in two different places?
Example:
What if I want to use the method of one controller of the same extension on the home page and the method of another controller on another page?
Create two different plugins.
Example: Instead of flexform
<switchableControllerActions>
<TCEforms>
<label>switchable controller actions</label>
<config>
<renderType>selectSingle</renderType>
<items>
<numIndex index="1">
<numIndex index="0">List</numIndex>
<numIndex index="1">Product->list</numIndex>
</numIndex>
<numIndex index="2">
<numIndex index="0">Show</numIndex>
<numIndex index="1">Product->show</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</switchableControllerActions>
Create two plugins.
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'extension',
'list',
[
'Product' => 'list'
]
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'extension',
'show',
[
'Product' => 'show'
]
);
More details see https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.3/Deprecation-89463-SwitchableControllerActions.html
From researching examples I have tried to create a switchable control action for my extension plugin, but it is not showing up. Can anybody help me figure out why?
In my ext_localconf.php I have the following:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'myeventplugin',
'Pi1',
[
'Events' => 'list, display'
],
// non-cacheable actions
[
'Events' => 'list, display'
]
);
In my ext_tables.php I have the following:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'myeventplugin',
'Pi1',
'Events'
);
$pluginSignature = 'myeventplugin_Pi1';
$TCA['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:myeventplugin/Configuration/FlexForms/flexform_pi1.xml');
In my Configuration/FlexForms/flexform_pi1.xml I have the following:
<?xml version="1.0" encoding="UTF-8"?>
<T3DataStructure>
<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>Events Plugin Config</sheetTitle>
</TCEforms>
<type>
array
</type>
<el>
<switchableControllerActions>
<TCEforms>
<label>View</label>
<onChange>reload</onChange>
<config>
<type>select</type>
<renderType>selectSingle</renderType>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0">Event List</numIndex>
<numIndex index="1">Events->list</numIndex>
</numIndex>
<numIndex index="1" type="array">
<numIndex index="0">Event Display</numIndex>
<numIndex index="1">Events->display</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</switchableControllerActions>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
When I include the plugin I don't see the additional select menu that I have created, therefore I can't specify which action I want it to call.
I thought that perhaps the $pluginSignature variable was incorrect due to the casing. Therefore in ext_tables.php in have tried the following:
$extensionName = strtolower(\TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY));
$pluginSignature = $extensionName.'_'.'Pi1';
and
$extensionName = strtolower(\TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY));
$pluginSignature = $extensionName.'_'.'pi1';
and
$pluginSignature = 'myeventplugin_Pi1';
and
$pluginSignature = 'myeventplugin_pi1';
...but still no luck
I have a look in my last extension: in ext_tables.php i wrote
$extensionName = strtolower(\TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($extKey));
$pluginName = strtolower('plg');
$pluginSignature = $extensionName.'_'.$pluginName;
so, im my case $pluginSignature = 'thoffer_plg', in your case it has to be 'myeventplugin_pi1'.
Next lines:
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist'][$pluginSignature] = 'layout,select_key,pages,recursive';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:'.$extKey . '/Configuration/FlexForms/contentPlugin.xml');
This is functional for me, in your case it looks ok. The best way is to reinstall the extension, if you change values for flexforms, because this is normally deeply cached.
I tried to to make it possible to configure the FE plugins of my own extension. The flexform configurion I tried doesn't show up in the backend.
Why it doesn't work and what do I need to change?
I'm working with Typo3 8.7.3.
Here are the relevant code parts:
ext_tables.php
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'Fmogge.'.$extKey,
'Nextcourse',
'Nächste Kurse'
);
$extensionName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY);
$frontendpluginName = 'Nextcourse';
$pluginSignature = strtolower($extensionName).'_'.strtolower($frontendpluginName);
$TCA['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:'.$_EXTKEY.'/Configuration/FlexForms/Nextcourse.xml');
Configuration/FlexForms/Nextcourse.xml
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3DataStructure>
<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>Optionen</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.ort>
<TCEforms>
<label>Ort wählen</label>
<config>
<type>select</type>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0"></numIndex>
<numIndex index="1"></numIndex>
</numIndex>
</items>
<foreign_table>tx_coursemanager_domain_model_ort</foreign_table>
<foreign_table_where>
AND elterndatensatz = 0
</foreign_table_where>
</config>
</TCEforms>
</settings.ort>
</el>
</ROOT>
</sDEF>
</sheets>
You can Use GLOBAL variables like below. it's work for me.
Just replace below line in your ext_tables.php file
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
In your ext_tables.php change syntax of $extKey to $_EXTKEY which will solve your issue, like:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'Fmogge.'.$_EXTKEY,
'Nextcourse',
'Nächste Kurse'
);
$extensionName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY);
$frontendpluginName = 'Nextcourse';
$pluginSignature = strtolower($extensionName).'_'.strtolower($frontendpluginName);
$TCA['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:'.$_EXTKEY.'/Configuration/FlexForms/Nextcourse.xml');
Hint: Avoid using $_EXTKEY in the future, use extension key as string instead. It has been changed in core and various 3rd party extensions. It helps, when you move such configs to folder Configuration/TCA/.. where $_EXTKEY is not available.
Your flexform file misses closing tag for T3DataStructure like:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3DataStructure>
<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>Optionen</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.ort>
<TCEforms>
<label>Ort wählen</label>
<config>
<type>select</type>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0"></numIndex>
<numIndex index="1"></numIndex>
</numIndex>
</items>
<foreign_table>tx_coursemanager_domain_model_ort</foreign_table>
<foreign_table_where>
AND elterndatensatz = 0
</foreign_table_where>
</config>
</TCEforms>
</settings.ort>
</el>
</ROOT>
</sDEF>
</sheets>
<T3DataStructure>
This is my code. I don't know where is the mistake? Please refere following code and help me
$pluginSignature = str_replace('_','',$_EXTKEY) . '_rock';
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin( 'Rocktechnolabs.' . $_EXTKEY, 'rock', 'THE FAQS' );
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForms/flexform_rock.xml');
in Configuration/FlexForms/flexform_rock.xml
<T3DataStructure>
<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>Function</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<switchableControllerActions>
<TCEforms>
<label>Select function</label>
<config>
<type>select</type>
<items>
<numIndex index="0">
<numIndex index="0">List</numIndex>
<numIndex index="1">Faq->list</numIndex>
</numIndex>
<numIndex index="1">
<numIndex index="0">Search</numIndex>
<numIndex index="1">Faq->search</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</switchableControllerActions>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
I tried a lot but i am not getting flexform during select plugin. Can you help me to find out the mistake?
You must add the flexform field to the subtypes_addlist:
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
make sure your $pluginSignature matches result of $pluginSignature within ExtensionUtility::registerPlugin().
This is what's happening in that method:
$extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
$pluginSignature = strtolower($extensionName) . '_' . strtolower($pluginName);
To me this looks different :)
Adding $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform'; as Rene suggested is important as well.
In Flexform I have a tree view where I can select categories for my product. But it shows all three languages. It should only show the language that is the same as the element language.
What did I miss?
<T3DataStructure>
<meta type="array">
<langChildren type="integer">0</langChildren>
<langDisable type="integer">1</langDisable>
</meta>
<sheets>
<main>
<ROOT>
<TCEforms>
<sheetTitle>Options</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.flexform.showCategory>
<TCEforms>
<exclude>1</exclude>
<label>Vælg kategori 1:</label>
<config>
<type>select</type>
<renderMode>tree</renderMode>
<treeConfig>
<parentField>maincategory</parentField>
<appearance>
<expandAll>FALSE</expandAll>
<showHeader>TRUE</showHeader>
</appearance>
</treeConfig>
<size>10</size>
<minitems>0</minitems>
<maxitems>999</maxitems>
<autoSizeMax>5</autoSizeMax>
<multiple>0</multiple>
<foreign_table>tx_origproducts_domain_model_category</foreign_table>
<!-- ###STORAGE_PID### is set by the field GENERAL STORAGE PAGE on the page record - or a parent page record to affect a hole branch -->
<foreign_table_where></foreign_table_where>
<size>10</size>
<items type="array">
<numIndex index="100">
<numIndex index="0">Alle</numIndex>
<numIndex index="1">-1</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</settings.flexform.showCategory>
</el>
</ROOT>
</main>s
</sheets>
Here is a snippet that only shows the foreign entries of the same language.
<foreign_table_where>AND (sys_language_uid=CAST('###REC_FIELD_sys_language_uid###' AS UNSIGNED) OR sys_language_uid = '-1') AND tx_origproducts_domain_model_category.deleted = 0 AND tx_origproducts_domain_model_category.hidden = 0</foreign_table_where>