Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To pass an array using TYPO3 Flexform XML and itemsProcConfig, first, define the form field for the array in the Flexform XML file. For example, to define a dropdown list field for an array of colors, use the following code:

<settings.colors>
    <TCEforms>
        <label>Colors:</label>
        <config>
            <type>select</type>
            <itemsProcConfig>
                <userFunc>Vendor\Extension\Hooks\FlexFormHooks->processColorList</userFunc>
            </itemsProcConfig>
        </config>
    </TCEforms>
</settings.colors>

Then, create a PHP class and method to handle the processing of the array items. This class and method should convert the array into a format that can be used in the dropdown list. Here is an example:

<?php
namespace Vendor\Extension\Hooks;

class FlexFormHooks
{
    public function processColorList(&$config)
    {
        $colorArray = [
            'red' => 'Red',
            'blue' => 'Blue',
            'green' => 'Green'
        ];

        foreach ($colorArray as $value => $label) {
            $config[] = [$label, $value];
        }
    }
}

This method takes the form field configuration and sets it to the array items by looping through the array and adding the values and labels to the $config array.

Finally, in the TYPO3 extension, register the FlexForm Hooks class and method:

$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'][\Vendor\Extension\Domain\Model\MyModel::class]['before'][\Vendor\Extension\Hooks\FlexFormHooks::class] = [
    'processFlexFormData',
];

With this, the FlexForm will be able to pass an array using itemsProcConfig.