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.includeCategories is available as $this->settings['includeCategories'].

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.

packages/my_extension/Classes/Controller/SomeController.php
$includeCategories = (bool) ($this->settings['includeCategories'] ?? false);
Copied!

FlexFormService: Read FlexForms values in PHP

You can use the \FlexFormService 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.

FlexFormService->convertFlexFormContentToArray returns an array that is suitable for most use cases:

EXT:my_extension/Classes/Controller/NonExtbaseController.php
<?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);
    }
}
Copied!

Read FlexForm data while preserving internal structure

The result of GeneralUtility::xml2array() preserves the internal structure of the XML FlexForm, and is usually used to modify a FlexForm string.

$flexFormStructure = GeneralUtility::xml2array($flexFormString);
Copied!

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
    }
  }
}
Copied!

The key flexform is followed by the field which hold the FlexForm data (pi_flexform) and the name of the property whose content should be retrieved (settings.categories).

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 {myOutputVariable}:

my_content = FLUIDTEMPLATE
my_content {
  dataProcessing {
    10 = flex-form
    10.fieldName = my_flexform_field
    10.as = myOutputVariable
  }
}
Copied!