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

Public Member Functions

 __construct (private readonly EventDispatcherInterface $eventDispatcher,)
 
string getDataStructureIdentifier (array $fieldTca, string $tableName, string $fieldName, array $row)
 
array parseDataStructureByIdentifier (string $identifier)
 
 cleanFlexFormXML (string $table, string $field, array $row)
 
 flexArray2Xml (array $array)
 

Protected Member Functions

 migrateFlexFormTcaRecursive (array $structure)
 
 getDefaultIdentifier (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)
 
 migrateAndPrepareFlexTca (array $dataStructure)
 
array prepareCategoryFields (array $dataStructureSheets)
 
array prepareFileFields (array $dataStructureSheets)
 

Detailed Description

Service class to help with TCA type="flex" details.

This service provides various helpers to determine the data structure of flex form fields and to maintain integrity of flex form related details in general.

Definition at line 39 of file FlexFormTools.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::__construct ( private readonly EventDispatcherInterface  $eventDispatcher)

Definition at line 41 of file FlexFormTools.php.

Member Function Documentation

◆ cleanFlexFormXML()

TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::cleanFlexFormXML ( string  $table,
string  $field,
array  $row 
)

Clean up FlexForm value XML to hold only the values it may according to its Data Structure. The order of tags will follow that of the data structure.

Signature may change, for instance to split 'DS finding' and flexArray2Xml(), which would allow broader use of the method. It is currently consumed by cleanup:flexforms CLI only.

Definition at line 159 of file FlexFormTools.php.

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

◆ convertDataStructureToArray()

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

◆ ensureDefaultSheet()

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

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

Definition at line 544 of file FlexFormTools.php.

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

◆ flexArray2Xml()

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

Convert FlexForm data array to XML

Definition at line 228 of file FlexFormTools.php.

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.

Parameters
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
Returns
‪string Identifier JSON string
Exceptions

Definition at line 81 of file FlexFormTools.php.

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

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

◆ getDataStructureIdentifierFromTcaArray()

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

Find matching data structure in TCA ds array.

Data structure is defined in 'ds' config array, optionally with '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', ];

Parameters
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
Returns
‪array Identifier as array, see example above
Exceptions
InvalidCombinedPointerFieldException
InvalidSinglePointerFieldException
InvalidTcaException

Definition at line 362 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 
)
protected

Returns the default data structure identifier.

Parameters
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
Exceptions
InvalidCombinedPointerFieldException
InvalidSinglePointerFieldException
InvalidTcaException

Definition at line 300 of file FlexFormTools.php.

References 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)
protected

◆ migrateAndPrepareFlexTca()

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

◆ migrateFlexFormTcaRecursive()

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

Recursively migrate flex form TCA

Definition at line 253 of file FlexFormTools.php.

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

◆ 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.

Parameters
string$identifier‪JSON string to find the data structure location
Returns
‪array Parsed and normalized data structure
Exceptions
InvalidIdentifierException

Definition at line 120 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(), TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\migrateAndPrepareFlexTca(), and TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools\resolveFileDirectives().

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

◆ prepareCategoryFields()

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

Prepare type=category fields if given.

NOTE: manyToMany relationships are not supported!

Parameters
array$dataStructureSheets
Returns
‪array The processed $dataStructureSheets

Definition at line 610 of file FlexFormTools.php.

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

◆ prepareFileFields()

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

Prepare type=file fields if given.

Returns
‪array The processed $dataStructureSheets

Definition at line 684 of file FlexFormTools.php.

References TYPO3\CMS\Core\Configuration\Tca\TcaPreparation\prepareFileExtensions().

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

◆ resolveFileDirectives()

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

Resolve FILE:EXT and EXT: for single sheets

Definition at line 562 of file FlexFormTools.php.

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

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