Ask Your Question
1

How can an array be passed using typo3 flexform xml and itemsProcConfig?

asked 2022-12-31 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-10-11 03:00:00 +0000

plato gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-12-31 11:00:00 +0000

Seen: 16 times

Last updated: Oct 11 '21