Reading FlexForm settings
FlexForms can be used to store data within an XML structure inside a single DB column.
Reading FlexForm settings in an Extbase controller
Plugin settings are available in the
$this->settings
array in the
Extbase controller.
TypoScript settings are overridden by non-empty FlexForm settings in the plugin's content element.
Only FlexForm settings prefixed with settings.
are available in the controllers
$this->settings
array. For example, FlexForm field settings.
is available as $this->settings
.
Do not rely on any key in the
$this->settings
array being set and always
cast it to the appropriate type. PHP errors might be triggered if a
value is not defined in the plugin.
$includeCategories = (bool) ($this->settings['includeCategories'] ?? false);
FlexFormService: Read FlexForms values in PHP
You can use the
\Flex
to read
the content of a FlexForm field.
This is useful in plain controllers without Extbase support, or in contexts like console commands or middleware where no settings are available.
Flex
returns an array that is
suitable for most use cases:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Mvc\Controller;
use TYPO3\CMS\Core\Service\FlexFormService;
final readonly class NonExtbaseController
{
public function __construct(
private FlexFormService $flexFormService,
) {}
public function indexAction(array $ttContentRow): void
{
$flexformData = $this->loadFlexForm($ttContentRow['pi_flexform'] ?? '');
// Do something
}
private function loadFlexForm(string $field): array
{
if ($field === '') {
return [];
}
return $this->flexFormService->convertFlexFormContentToArray($field);
}
}
Read FlexForm data while preserving internal structure
The result of
General
preserves the internal
structure of the XML FlexForm, and is usually used to modify a FlexForm
string.
$flexFormStructure = GeneralUtility::xml2array($flexFormString);
See also section How to modify FlexForms from PHP.
TypoScript: Reading flexform data
It is possible to read FlexForm properties in TypoScript:
lib.flexformContent = CONTENT
lib.flexformContent {
table = tt_content
select {
pidInList = this
}
renderObj = COA
renderObj {
10 = TEXT
10 {
data = flexform:pi_flexform:settings.categories
}
}
}
The key flexform
is followed by the field which hold the FlexForm data
(pi_
) and the name of the property whose content should be retrieved
(settings.
).
See also
flex-form data processor
If you have defined
FLUIDTEMPLATE
in TypoScript, you can use
flex-form data processor.
This example would make your FlexForm data available as a Fluid variable
{my
: