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/

Configuration/TCA/Overrides/tt_content.php ›››

$extName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY);
$pluginSignature = strtolower($extName).'_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:

  • $pluginSignature: extname_pluginname (lowercase, no underscores within the two parts of the pluginSignature)
  • FlexForm is being added to the form (see below)

(Optional) For a special select list called in the flex form, create a class: Classes/Utility/FlexFormSelections.php

!! Don’t forget to make that class available in the T3 autoloader by going to Admin Tools → Maintenance in the T3 Backend and, in the box Rebuild PHP Autoload Information hit the button Dump Autoload … if your T3 installation does not have a typo3conf/autoload folder you might need to include the class in the above mentioned script instead.

<?php
namespace VendorName\YourExt\Utility;

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

/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\Utility\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.