FlexFormTools
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.
Attributes
- #[Autoconfigure]
- $public: true
Table of Contents
Methods
- __construct() : mixed
- cleanFlexFormXML() : string
- Clean up FlexForm value XML to hold only the values it may according to its Data Structure.
- flexArray2Xml() : string
- Convert FlexForm data array to XML
- getDataStructureIdentifier() : string
- 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.
- parseDataStructureByIdentifier() : array<string|int, mixed>
- Parse a data structure identified by $identifier to the final data structure array.
- convertDataStructureToArray() : array<string|int, mixed>
- ensureDefaultSheet() : array<string|int, mixed>
- Ensures a data structure has a default sheet, and no duplicate data
- getDataStructureIdentifierFromTcaArray() : array<string|int, mixed>
- Find matching data structure in TCA ds array.
- getDefaultIdentifier() : array<string|int, mixed>
- Returns the default data structure identifier.
- getDefaultStructureForIdentifier() : string
- resolveFileDirectives() : array<string|int, mixed>
- Resolve FILE:EXT and EXT: for single sheets
Methods
__construct()
public
__construct(EventDispatcherInterface $eventDispatcher, TcaMigration $tcaMigration, TcaPreparation $tcaPreparation) : mixed
Parameters
- $eventDispatcher : EventDispatcherInterface
- $tcaMigration : TcaMigration
- $tcaPreparation : TcaPreparation
cleanFlexFormXML()
Clean up FlexForm value XML to hold only the values it may according to its Data Structure.
public
cleanFlexFormXML(string $table, string $field, array<string|int, mixed> $row) : string
The order of tags will follow that of the data structure.
Parameters
- $table : string
- $field : string
- $row : array<string|int, mixed>
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.
Return values
stringflexArray2Xml()
Convert FlexForm data array to XML
public
flexArray2Xml(array<string|int, mixed> $array) : string
Parameters
- $array : array<string|int, mixed>
Return values
stringgetDataStructureIdentifier()
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.
public
getDataStructureIdentifier(array<string|int, mixed> $fieldTca, string $tableName, string $fieldName, array<string|int, mixed> $row) : string
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
- $fieldTca : array<string|int, mixed>
-
Full TCA of the field in question that has type=flex set
- $tableName : string
-
The table name of the TCA field
- $fieldName : string
-
The field name
- $row : array<string|int, mixed>
-
The data row
Tags
Return values
string —Identifier JSON string
parseDataStructureByIdentifier()
Parse a data structure identified by $identifier to the final data structure array.
public
parseDataStructureByIdentifier(string $identifier) : array<string|int, mixed>
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 afterward 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
- $identifier : string
-
JSON string to find the data structure location
Tags
Return values
array<string|int, mixed> —Parsed and normalized data structure
convertDataStructureToArray()
protected
convertDataStructureToArray(string|array<string|int, mixed> $dataStructure) : array<string|int, mixed>
Parameters
- $dataStructure : string|array<string|int, mixed>
Return values
array<string|int, mixed>ensureDefaultSheet()
Ensures a data structure has a default sheet, and no duplicate data
protected
ensureDefaultSheet(array<string|int, mixed> $dataStructure) : array<string|int, mixed>
Parameters
- $dataStructure : array<string|int, mixed>
Return values
array<string|int, mixed>getDataStructureIdentifierFromTcaArray()
Find matching data structure in TCA ds array.
protected
getDataStructureIdentifierFromTcaArray(array<string|int, mixed> $fieldTca, string $tableName, string $fieldName, array<string|int, mixed> $row) : array<string|int, mixed>
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
- $fieldTca : array<string|int, mixed>
-
Full TCA of the field in question that has type=flex set
- $tableName : string
-
The table name of the TCA field
- $fieldName : string
-
The field name
- $row : array<string|int, mixed>
-
The data row
Tags
Return values
array<string|int, mixed> —Identifier as array, see example above
getDefaultIdentifier()
Returns the default data structure identifier.
protected
getDefaultIdentifier(array<string|int, mixed> $fieldTca, string $tableName, string $fieldName, array<string|int, mixed> $row) : array<string|int, mixed>
Parameters
- $fieldTca : array<string|int, mixed>
-
Full TCA of the field in question that has type=flex set
- $tableName : string
-
The table name of the TCA field
- $fieldName : string
-
The field name
- $row : array<string|int, mixed>
-
The data row
Tags
Return values
array<string|int, mixed>getDefaultStructureForIdentifier()
protected
getDefaultStructureForIdentifier(array<string|int, mixed> $identifier) : string
Parameters
- $identifier : array<string|int, mixed>
Return values
stringresolveFileDirectives()
Resolve FILE:EXT and EXT: for single sheets
protected
resolveFileDirectives(array<string|int, mixed> $dataStructure) : array<string|int, mixed>
Parameters
- $dataStructure : array<string|int, mixed>