Building a TYPO3 extension in Extbase/Fluid

Plugin Options for content elements: FlexForms

see also:

File paths are relative to the root of your extension /typo3conf/ext/your_extension/

ext_tables.php ›››

if(TYPO3_MODE == 'BE') {
        include_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('your_ext').'Resources/class.selections.php');
}
$ext_name = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY);
$pluginSignature = strtolower($ext_name).'_yourplugin';
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:your_ext/Configuration/FlexForms/flexform_xyz.xml');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSignature, 'FILE:EXT:your_ext/Configuration/FlexForms/flexform_xyz.xml');

Notes:

  • the included php class selections will return select fields for the FlexForm (see below)
  • $pluginSignature: extname_pluginname (lowercase, no underscores within the two parts of the pluginSignature)
  • FlexForm is being added to the form (see below)

The included class “selections” that sets up the select list

<?php
namespace VendorName\YourExt\Resources;

// this class will setup the select lists for the plugin options in tt_content form
class selections {
        public function listOptions($config) {
                $optionList[0] = array(0 => 'Make your selection', 1 => 0); // 0: option text; 1: option value
                $optionList[1] = array(0 => 'First Option', 1 => 1); // 0: option text; 1: option value
                $optionList[2] = array(0 => 'Second Option', 1 => 2); // 0: option text; 1: option value
                $config['items'] = array_merge($config['items'], $optionList);
                return $config;
        }
}

if(defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/your_ext/Resources/class.selections.php']) {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/your_ext/Resources/class.selections.php']);
}

?>
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/your_ext/Resources/class.selections.php']);
}

?>

/Configuration/FlexForms/flexform_xyz.xml

<?xml version="1.0"?>
<!-- this file contains the plugin options (tt_content form) -->
<T3DataStructure>
        <meta>
                <!-- langDisable: important! – otherwise there will be a big fat DEF: below the header Plugin Options -->
                <langDisable>1</langDisable>
        </meta>
        <sheets>
                <sDEF>
                        <ROOT>
                                <TCEforms>
                                        <sheetTitle>LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xml:tx_yourext_flexform.tab1</sheetTitle>
                                </TCEforms>
                                <type>array</type>
                                <el>
                                        <settings.flexform.yourSettingName>
                                                <TCEforms>
                                                        <exclude>1</exclude>
                                                        <label>LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xml:tx_yourext_flexform.formFieldName</label>
                                                        <config>
                                                                <type>select</type>
                                                                <itemsProcFunc>VendorName\YourExt\Resources\selections->listOptions</itemsProcFunc>
                                                                <size>1</size>
                                                                <maxitems>1</maxitems>
                                                        </config>
                                                </TCEforms>
                                        </settings.flexform.yourSettingName>
                                </el>
                        </ROOT>
                </sDEF>
        </sheets>
</T3DataStructure>
        </sheets>
</T3DataStructure>

For more information on how to build the XML FlexForm see this tutorial
 (already mentioned above)
Take care to wrap the single fields within <el></el> with <settings.flexform.yourSettingName> </settings.flexform.yourSettingName> to make them available as settings in the Controller
NOTE: it should also be working without .flexform thus <settings.yourSettingName> but I haven’t checked

Calling the stored settings in the Controller function

  • use $this->settings['yourSettingName']
  • for a deeper settings structure use <settings.arrayName.yourSettingName> in the FlexForm and call it by $this->settings['arrayName']['yourSettingName']

Note, that the settings are NOT AVAILABLE in the Repository. So if you call a Repository method from your Controller method you must pass the settings.