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

Public Member Functions

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)
 
mixed & getArrayValueByPath ($pathArray, &$array)
 
mixed setArrayValueByPath ($pathArray, &$array, $value)
 
string flexArray2Xml ($array, $addPrologue=false)
 

Public Attributes

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

Protected Member Functions

array getDataStructureIdentifierFromRecord (array $fieldTca, string $tableName, string $fieldName, array $row)
 
array getDataStructureIdentifierFromTcaArray (array $fieldTca, string $tableName, string $fieldName, array $row)
 
mixed executeCallBackMethod ($methodName, array $parameterArray)
 

Detailed Description

Contains functions for manipulating flex form data

Definition at line 37 of file FlexFormTools.php.

Member Function Documentation

◆ cleanFlexFormXML()

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

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.

Parameters
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
Returns
‪string Clean XML from FlexForm field

Definition at line 899 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,
  $data,
  $PA,
  $path,
  $pObj 
)

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!)

Parameters
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
FlexFormTools$pObj‪caller

Definition at line 920 of file FlexFormTools.php.

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

◆ executeCallBackMethod()

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

Execute method on callback object

Parameters
string$methodName‪Method name to call
array$parameterArray‪Parameters
Returns
‪mixed Result of callback object

Definition at line 880 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

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

Definition at line 990 of file FlexFormTools.php.

References $GLOBALS, and $output.

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

◆ getArrayValueByPath()

mixed& TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::getArrayValueByPath (   $pathArray,
$array 
)

Get a value from a multi-dimensional array by giving a path "../../.." pointing to the element

Parameters
string$pathArray‪The path pointing to the value field, eg. test/2/title to access $array['test'][2]['title']
array$array‪Array to get value from. Passed by reference so the value returned can be used to change the value in the array!
Returns
‪mixed Value returned

Definition at line 938 of file FlexFormTools.php.

◆ 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 hooks 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 string
Exceptions

Definition at line 114 of file FlexFormTools.php.

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

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

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', ];

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
InvalidParentRowException
InvalidParentRowLoopException
InvalidParentRowRootException
InvalidPointerFieldValueException
InvalidTcaException

Definition at line 266 of file FlexFormTools.php.

References TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger(), TYPO3\CMS\Backend\Utility\BackendUtility\fixVersioningPid(), TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode(), and TYPO3\CMS\Backend\Utility\BackendUtility\workspaceOL().

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

◆ 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. 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', ];

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 432 of file FlexFormTools.php.

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

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

◆ 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
  • ‪EXT: prefix for sheets - if single sheets are in files (slightly different b/w compat syntax)
  • ‪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‪String to find the data structure location
Returns
‪array Parsed and normalized data structure
Exceptions
InvalidIdentifierException

Definition at line 575 of file FlexFormTools.php.

References $GLOBALS, and TYPO3\CMS\Core\Utility\GeneralUtility\xml2array().

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

◆ setArrayValueByPath()

mixed TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::setArrayValueByPath (   $pathArray,
$array,
  $value 
)

Set a value in a multi-dimensional array by giving a path "../../.." pointing to the element

Parameters
string$pathArray‪The path pointing to the value field, eg. test/2/title to access $array['test'][2]['title']
array$array‪Array to set value in. Passed by reference so the value returned can be used to change the value in the array!
mixed$value‪Value to set
Returns
‪mixed Value returned

Definition at line 963 of file FlexFormTools.php.

◆ traverseFlexFormXMLData()

bool string TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::traverseFlexFormXMLData (   $table,
  $field,
  $row,
  $callBackObj,
  $callBackMethod_value 
)

Handler for Flex Forms

Parameters
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
Returns
‪bool|string true on success, string if error happened (error string returned)

Definition at line 765 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,
  $editData,
$PA,
  $path = '' 
)

Recursively traversing flexform data according to data structure and element data

Parameters
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 819 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 68 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 74 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 50 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 43 of file FlexFormTools.php.