Using FlexForms

Basically the configuration of a FlexForm field is all about pointing to a data structure which contains the form rendering information.

For general information about the backbone of a Data Structure, please refer to the "<T3DataStructure>" chapter in the Core API manual.

Using FlexForms to configure plugins

FlexForms are commonly used in the tt_content table to register plugins.

Deprecated since version 14.0

Using ExtensionManagementUtility::addPiFlexFormValue() has been deprecated, use the 7th parameter of ExtensionUtility::registerPlugin() instead.

New in version 14.0

FlexForm definitions can be passed as the 7th parameter to ExtensionUtility::registerPlugin() when registering Extbase.

packages/my_extension/Configuration/TCA/Overrides/tt_content.php
<?php

use TYPO3\CMS\Extbase\Utility\ExtensionUtility;

ExtensionUtility::registerPlugin(
    'MyExtension',
    'MyPlugin',
    'My Plugin Title',
    'my-extension-icon',
    'plugins',
    'Plugin description',
    'FILE:EXT:myext/Configuration/FlexForm.xml'
);
Copied!

Configuring a table with a FlexForm

Changed in version 14.0

Use configuration option ds to either pass a file reference to the XML file containing the FlexForm or a string containing the FlexForm's XML:

EXT:styleguide/Configuration/TCA/tx_styleguide_flex.php
[
    'columns' => [
        'flex_file_1' => [
            'label' => 'flex_file_1 simple flexform in external file',
            'description' => 'field description',
            'config' => [
                'type' => 'flex',
                'ds' => 'FILE:EXT:styleguide/Configuration/FlexForms/Simple.xml',
            ],
        ],
    ],
]
Copied!

Essentially: Whenever a record is handled that has a column field definition with this TCA, the data structure defined in FILE:EXT:styleguide/Configuration/FlexForms/Simple.xml is parsed and the flex form defined in there is displayed.

Individual FlexForms by type

Changed in version 14.0

If the table has $GLOBALS['TCA'][$table]['ctrl']['type'] set, you can use columnsOverrides to set different FlexForms by type.

packages/my_extension/Configuration/TCA/tx_my_table.php
<?php

return [
    'ctrl' => [
        'title' => 'Table with special FlexForm per Type',
        'type' => 'my_type_field',
        'label' => 'uid',
    ],
    'columns' => [
        'my_type_field' => [
            // ...
        ],
        'pi_flexform' => [
            'config' => [
                // FlexFormDefault.xml is used if not overridden in the columnsOverrides
                'ds' => 'FILE:EXT:news/Configuration/FlexFormDefault.xml',
            ],
        ],
    ],
    'types' => [
        0 => [
            'showitem' => 'my_type_field, pi_flexform',
        ],
        1 => [
            'showitem' => 'my_type_field, pi_flexform',
            'columnsOverrides' => [
                'pi_flexform' => [
                    'config' => [
                        'ds' => 'FILE:EXT:news/Configuration/FlexForm1.xml',
                    ],
                ],
            ],
        ],
        2 => [
            'showitem' => 'my_type_field, pi_flexform',
            'columnsOverrides' => [
                'pi_flexform' => [
                    'config' => [
                        'ds' => 'FILE:EXT:news/Configuration/FlexForm2.xml',
                    ],
                ],
            ],
        ],
        3 => [
            'showitem' => 'my_type_field, pi_flexform',
        ],
    ],
];
Copied!

In the above example, type 0 and type 3 display the default FlexForm defined in file 'FILE:EXT:news/Configuration/FlexFormDefault.xml', and type 1 and 2 each display their individual FlexForms.