‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools Class Reference

Public Member Functions

 __construct (private ?EventDispatcherInterface $eventDispatcher=null,)
string getDataStructureIdentifier (array $fieldTca, string $tableName, string $fieldName, array $row)
array parseDataStructureByIdentifier (string $identifier)
bool string traverseFlexFormXMLData ($table, $field, $row, $callBackObj, $callBackMethod_value)
 traverseFlexFormXMLData_recurse ($dataStruct, $editData, &$PA, $path='')
string cleanFlexFormXML ($table, $field, $row)
 cleanFlexFormXML_callBackFunction ($dsArr, $data, $PA, $path, $pObj)
string flexArray2Xml ($array, $addPrologue=false)
 removeElementTceFormsRecursive (array $structure)
 migrateFlexFormTcaRecursive (array $structure)

Public Attributes

bool $reNumberIndexesOfSectionData = false
array $flexArray2Xml_options
object $callBackObj
array $cleanFlexFormXML = array( )

Protected Member Functions

 getDefaultIdentifier (array $fieldTca, string $tableName, string $fieldName, array $row)
array getDataStructureIdentifierFromRecord (array $fieldTca, string $tableName, string $fieldName, array $row)
array getDataStructureIdentifierFromTcaArray (array $fieldTca, string $tableName, string $fieldName, array $row)
 convertDataStructureToArray (string|array $dataStructure)
 getDefaultStructureForIdentifier (array $identifier)
 ensureDefaultSheet (array $dataStructure)
 resolveFileDirectives (array $dataStructure)
mixed executeCallBackMethod ($methodName, array $parameterArray)
array prepareCategoryFields (array $dataStructureSheets)
array prepareFileFields (array $dataStructureSheets)

Detailed Description

Contains functions for manipulating flex form data

The data structure identifier (array) has several commonly used elements (keys), but is generally undefined. Users of this system should be extra careful of what array keys are defined or not.

Recommended keys include:

  • ‪type
  • ‪tableName
  • ‪fieldName
  • ‪dataStructureKey

Definition at line 56 of file FlexFormTools.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::__construct ( private ?EventDispatcherInterface  $eventDispatcher = null)

Definition at line 95 of file FlexFormTools.php.

Member Function Documentation

◆ cleanFlexFormXML()

string TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::cleanFlexFormXML (   $table,

Cleaning up FlexForm XML to hold only the values it may according to its Data Structure. Also the order of tags will follow that of the data structure. BE CAREFUL: DO not clean records in workspaces unless IN the workspace! The Data Structure might resolve falsely on a workspace record when cleaned from Live workspace.

string$table‪Table name
string$field‪Field name of the flex form field in which the XML is found that should be cleaned.
array$row‪The record
‪string Clean XML from FlexForm field

Definition at line 867 of file FlexFormTools.php.

References TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\flexArray2Xml().

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\cleanFlexFormXML_callBackFunction().

◆ cleanFlexFormXML_callBackFunction()

TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::cleanFlexFormXML_callBackFunction (   $dsArr,

Call back function for \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools class Basically just setting the value in a new array (thus cleaning because only values that are valid are visited!)

array$dsArr‪Data structure for the current value
mixed$data‪Current value
array$PA‪Additional configuration used in calling function
string$path‪Path of value in DS structure

Definition at line 888 of file FlexFormTools.php.

References TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\cleanFlexFormXML(), and TYPO3\CMS\Core\Utility\ArrayUtility\setValueByPath().

◆ convertDataStructureToArray()

TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::convertDataStructureToArray ( string|array  $dataStructure)

◆ ensureDefaultSheet()

TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::ensureDefaultSheet ( array  $dataStructure)

Ensures a data structure has a default sheet, and no duplicate data

Definition at line 675 of file FlexFormTools.php.

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\parseDataStructureByIdentifier().

◆ executeCallBackMethod()

mixed TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::executeCallBackMethod (   $methodName,
array  $parameterArray 

Execute method on callback object

string$methodName‪Method name to call
‪mixed Result of callback object

Definition at line 848 of file FlexFormTools.php.

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\traverseFlexFormXMLData_recurse().

◆ flexArray2Xml()

string TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::flexArray2Xml (   $array,
  $addPrologue = false 

Convert FlexForm data array to XML

array$array‪Array to output in <T3FlexForms> XML
bool$addPrologue‪If set, the XML prologue is returned as well.
‪string XML content.

Definition at line 901 of file FlexFormTools.php.

References $GLOBALS, and $output.

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\cleanFlexFormXML().

◆ getDataStructureIdentifier()

string TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::getDataStructureIdentifier ( array  $fieldTca,
string  $tableName,
string  $fieldName,
array  $row 

The method locates a specific data structure from given TCA and row combination and returns an identifier string that can be handed around, and can be resolved to a single data structure later without giving $row and $tca data again.

Note: The returned syntax is meant to only specify the target location of the data structure. It SHOULD NOT be abused and enriched with data from the record that is dealt with. For instance, it is now allowed to add source record specific date like the uid or the pid! If that is done, it is up to the hook consumer to take care of possible side effects, eg. if the data handler copies or moves records around and those references change.

This method gets: Source data that influences the target location of a data structure This method returns: Target specification of the data structure

This method is "paired" with method getFlexFormDataStructureByIdentifier() that will resolve the returned syntax again and returns the data structure itself.

Both methods can be extended via events to return and accept additional identifier strings if needed, and to transmit further information within the identifier strings.

Note that the TCA for data structure definitions MUST NOT be overridden by 'columnsOverrides' or by parent TCA in an inline relation! This would create a huge mess.

Note: This method and the resolving methods below are well unit tested and document all nasty details this way.

array$fieldTca‪Full TCA of the field in question that has type=flex set
string$tableName‪The table name of the TCA field
string$fieldName‪The field name
array$row‪The data row
‪string Identifier JSON string

Definition at line 139 of file FlexFormTools.php.

References TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\getDefaultIdentifier().

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\traverseFlexFormXMLData().

◆ getDataStructureIdentifierFromRecord()

array TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::getDataStructureIdentifierFromRecord ( array  $fieldTca,
string  $tableName,
string  $fieldName,
array  $row 

The data structure is located in a record. This method resolves the record and returns an array to identify that record.

The example setup below looks in current row for a tx_templavoila_ds value. If not found, it will search the rootline (the table is a tree, typically pages) until a value in tx_templavoila_next_ds or tx_templavoila_ds is found. That value should then be an integer, that points to a record in tx_templavoila_datastructure, and then the data structure is found in field dataprot:

fieldTca = [ 'config' => [ 'type' => 'flex', 'ds_pointerField' => 'tx_templavoila_ds', 'ds_pointerField_searchParent' => 'pid', 'ds_pointerField_searchParent_subField' => 'tx_templavoila_next_ds', 'ds_tableField' => 'tx_templavoila_datastructure:dataprot', ] ]

More simple scenario without tree traversal and having a valid data structure directly located in field theFlexDataStructureField.

fieldTca = [ 'config' => [ 'type' => 'flex', 'ds_pointerField' => 'theFlexDataStructureField', ] ]

Example return array: [ 'type' => 'record', 'tableName' => 'tx_templavoila_datastructure', 'uid' => 42, 'fieldName' => 'dataprot', ];

array$fieldTca‪Full TCA of the field in question that has type=flex set
string$tableName‪The table name of the TCA field
string$fieldName‪The field name
array$row‪The data row
‪array Identifier as array, see example above

Definition at line 241 of file FlexFormTools.php.

References TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger(), TYPO3\CMS\Core\Database\Connection\PARAM_INT, and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\getDefaultIdentifier().

◆ getDataStructureIdentifierFromTcaArray()

array TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::getDataStructureIdentifierFromTcaArray ( array  $fieldTca,
string  $tableName,
string  $fieldName,
array  $row 

Find matching data structure in TCA ds array.

Data structure is defined in 'ds' config array. Also, there can be a ds_pointerField

fieldTca = [ 'config' => [ 'type' => 'flex', 'ds' => [ 'aName' => '<T3DataStructure>...' OR 'FILE:...' ], 'ds_pointerField' => 'optionalSetting,upToTwoCommaSeparatedFieldNames', ] ]

This method returns an array of the form: [ 'type' => 'Tca:', 'tableName' => $tableName, 'fieldName' => $fieldName, 'dataStructureKey' => $key, ];

Example: [ 'type' => 'Tca:', 'tableName' => 'tt_content', 'fieldName' => 'pi_flexform', 'dataStructureKey' => 'powermail_pi1,list', ];

array$fieldTca‪Full TCA of the field in question that has type=flex set
string$tableName‪The table name of the TCA field
string$fieldName‪The field name
array$row‪The data row
‪array Identifier as array, see example above

Definition at line 406 of file FlexFormTools.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\getDefaultIdentifier().

◆ getDefaultIdentifier()

TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::getDefaultIdentifier ( array  $fieldTca,
string  $tableName,
string  $fieldName,
array  $row 

Returns the default data structure identifier.

array$fieldTca‪Full TCA of the field in question that has type=flex set
string$tableName‪The table name of the TCA field
string$fieldName‪The field name
array$row‪The data row

Definition at line 160 of file FlexFormTools.php.

References TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\getDataStructureIdentifierFromRecord(), and TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\getDataStructureIdentifierFromTcaArray().

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\getDataStructureIdentifier().

◆ getDefaultStructureForIdentifier()

TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::getDefaultStructureForIdentifier ( array  $identifier)

◆ migrateFlexFormTcaRecursive()

TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::migrateFlexFormTcaRecursive ( array  $structure)

Recursively migrate flex form TCA

Definition at line 1101 of file FlexFormTools.php.

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\resolveFileDirectives().

◆ parseDataStructureByIdentifier()

array TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::parseDataStructureByIdentifier ( string  $identifier)

Parse a data structure identified by $identifier to the final data structure array. This method is called after getDataStructureIdentifier(), finds the data structure and returns it.

Hooks allow to manipulate the find logic and to post process the data structure array.

Note that the TCA for data structure definitions MUST NOT be overridden by 'columnsOverrides' or by parent TCA in an inline relation! This would create a huge mess.

After the data structure definition is found, the method resolves:

  • ‪FILE:EXT: prefix of the data structure itself - the ds is in a file
  • ‪FILE:EXT: prefix for sheets - if single sheets are in files
  • ‪Create an sDEF sheet if the data structure has non, yet.

After that method is run, the data structure is fully resolved to an array, and same base normalization is done: If the ds did not contain a sheet, it will have one afterwards as "sDEF"

This method gets: Target specification of the data structure. This method returns: The normalized data structure parsed to an array.

Read the unit tests for nasty details.

string$identifier‪JSON string to find the data structure location
‪array Parsed and normalized data structure

Definition at line 548 of file FlexFormTools.php.

References TYPO3\CMS\Webhooks\Message\$identifier, TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\convertDataStructureToArray(), TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\ensureDefaultSheet(), TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\getDefaultStructureForIdentifier(), and TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\resolveFileDirectives().

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\traverseFlexFormXMLData().

◆ prepareCategoryFields()

array TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::prepareCategoryFields ( array  $dataStructureSheets)

Prepare type=category fields if given.

NOTE: manyToMany relationships are not supported!

‪array The processed $dataStructureSheets

Definition at line 921 of file FlexFormTools.php.

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\resolveFileDirectives().

◆ prepareFileFields()

array TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::prepareFileFields ( array  $dataStructureSheets)

Prepare type=file fields if given.

‪array The processed $dataStructureSheets

Definition at line 1004 of file FlexFormTools.php.

References TYPO3\CMS\Core\Preparations\TcaPreparation\prepareFileExtensions().

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\resolveFileDirectives().

◆ removeElementTceFormsRecursive()

TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::removeElementTceFormsRecursive ( array  $structure)

Remove "TCEforms" key from all elements in data structure to simplify further parsing.

Example config: ['config']['ds']['sheets']['sDEF']['ROOT']['el']['anElement']['TCEforms']['label'] becomes ['config']['ds']['sheets']['sDEF']['ROOT']['el']['anElement']['label']


['ROOT']['TCEforms']['sheetTitle'] becomes ['ROOT']['sheetTitle']

This method serves as a compatibility layer and will be removed in TYPO3 v13.

Definition at line 1063 of file FlexFormTools.php.

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\resolveFileDirectives().

◆ resolveFileDirectives()

◆ traverseFlexFormXMLData()

bool string TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::traverseFlexFormXMLData (   $table,

Handler for Flex Forms

string$table‪The table name of the record
string$field‪The field name of the flexform field to work on
array$row‪The record data array
object$callBackObj‪Object in which the call back function is located
string$callBackMethod_value‪Method name of call back function in object for values
‪bool|string true on success, string if error happened (error string returned)

Definition at line 733 of file FlexFormTools.php.

References TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\$callBackObj, $GLOBALS, TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\getDataStructureIdentifier(), TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\parseDataStructureByIdentifier(), TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\traverseFlexFormXMLData_recurse(), and TYPO3\CMS\Core\Utility\GeneralUtility\xml2array().

◆ traverseFlexFormXMLData_recurse()

TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::traverseFlexFormXMLData_recurse (   $dataStruct,
  $path = '' 

Recursively traversing flexform data according to data structure and element data

array$dataStruct‪(Part of) data structure array that applies to the sub section of the flexform data we are processing
array$editData‪(Part of) edit data array, reflecting current part of data structure
array$PA‪Additional parameters passed.
string$path‪Telling the "path" to the element in the flexform XML

Definition at line 787 of file FlexFormTools.php.

References TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\executeCallBackMethod().

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\traverseFlexFormXMLData().

Member Data Documentation

◆ $callBackObj

object TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::$callBackObj

Reference to object called

Definition at line 87 of file FlexFormTools.php.

Referenced by TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\traverseFlexFormXMLData().

◆ $cleanFlexFormXML

array TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::$cleanFlexFormXML = array( )

Used for accumulation of clean XML

Definition at line 93 of file FlexFormTools.php.

◆ $flexArray2Xml_options

array TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::$flexArray2Xml_options
Initial value:
= array(
'parentTagMap' => [
'data' => 'sheet',
'sheet' => 'language',
'language' => 'field',
'el' => 'field',
'field' => 'value',
'field:el' => 'el',
'el:_IS_NUM' => 'section',
'section' => 'itemType',
'disableTypeAttrib' => 2,

Options for array2xml() for flexform. This will map the weird keys from the internal array to tags that could potentially be checked with a DTD/schema

Definition at line 69 of file FlexFormTools.php.

◆ $reNumberIndexesOfSectionData

bool TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::$reNumberIndexesOfSectionData = false

If set, section indexes are re-numbered before processing

Definition at line 62 of file FlexFormTools.php.