TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FlexFormTools Class Reference

Public Member Functions

 getDataStructureIdentifier (array $fieldTca, string $tableName, string $fieldName, array $row)
 
 parseDataStructureByIdentifier (string $identifier)
 
 traverseFlexFormXMLData ($table, $field, $row, $callBackObj, $callBackMethod_value)
 
 traverseFlexFormXMLData_recurse ($dataStruct, $editData, &$PA, $path= '')
 
 cleanFlexFormXML ($table, $field, $row)
 
 cleanFlexFormXML_callBackFunction ($dsArr, $data, $PA, $path, $pObj)
 
getArrayValueByPath ($pathArray, &$array)
 
 setArrayValueByPath ($pathArray, &$array, $value)
 
 flexArray2Xml ($array, $addPrologue=false)
 

Public Attributes

 $reNumberIndexesOfSectionData = false
 
 $flexArray2Xml_options
 
 $callBackObj = null
 
 $cleanFlexFormXML = []
 

Protected Member Functions

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

Detailed Description

Contains functions for manipulating flex form data

Definition at line 35 of file FlexFormTools.php.

Member Function Documentation

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$tableTable name
string$fieldField name of the flex form field in which the XML is found that should be cleaned.
array$rowThe record
Returns
string Clean XML from FlexForm field

Definition at line 886 of file FlexFormTools.php.

References FlexFormTools\flexArray2Xml(), and GeneralUtility\makeInstance().

Referenced by FlexFormTools\cleanFlexFormXML_callBackFunction().

cleanFlexFormXML_callBackFunction (   $dsArr,
  $data,
  $PA,
  $path,
  $pObj 
)

Call back function for class Basically just setting the value in a new array (thus cleaning because only values that are valid are visited!)

Parameters
array$dsArrData structure for the current value
mixed$dataCurrent value
array$PAAdditional configuration used in calling function
string$pathPath of value in DS structure
FlexFormTools$pObjcaller
Returns
void

Definition at line 908 of file FlexFormTools.php.

References FlexFormTools\cleanFlexFormXML().

executeCallBackMethod (   $methodName,
array  $parameterArray 
)
protected

Execute method on callback object

Parameters
string$methodNameMethod name to call
array$parameterArrayParameters
Returns
mixed Result of callback object

Definition at line 867 of file FlexFormTools.php.

Referenced by FlexFormTools\traverseFlexFormXMLData_recurse().

flexArray2Xml (   $array,
  $addPrologue = false 
)

Convert FlexForm data array to XML

Parameters
array$arrayArray to output in <T3FlexForms> XML
bool$addPrologueIf set, the XML prologue is returned as well.
Returns
string XML content.

Definition at line 978 of file FlexFormTools.php.

References $GLOBALS, and GeneralUtility\array2xml().

Referenced by FlexFormTools\cleanFlexFormXML().

& getArrayValueByPath (   $pathArray,
$array 
)

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

Parameters
string$pathArrayThe path pointing to the value field, eg. test/2/title to access $array['test'][2]['title']
array$arrayArray 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 926 of file FlexFormTools.php.

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 belowe are well unit tested and document all nasty details this way.

Parameters
array$fieldTcaFull TCA of the field in question that has type=flex set
string$tableNameThe table name of the TCA field
string$fieldNameThe field name
array$rowThe data row
Returns
string Identifier string
Exceptions
RuntimeException If TCA is misconfigured

Definition at line 111 of file FlexFormTools.php.

References $GLOBALS, FlexFormTools\getDataStructureIdentifierFromRecord(), FlexFormTools\getDataStructureIdentifierFromTcaArray(), and GeneralUtility\makeInstance().

Referenced by FlexFormTools\traverseFlexFormXMLData().

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$fieldTcaFull TCA of the field in question that has type=flex set
string$tableNameThe table name of the TCA field
string$fieldNameThe field name
array$rowThe data row
Returns
array Identifier as array, see example above
Exceptions
InvalidParentRowException
InvalidParentRowLoopException
InvalidParentRowRootException
InvalidPointerFieldValueException
InvalidTcaException

Definition at line 247 of file FlexFormTools.php.

References MathUtility\canBeInterpretedAsInteger(), BackendUtility\fixVersioningPid(), GeneralUtility\makeInstance(), GeneralUtility\trimExplode(), and BackendUtility\workspaceOL().

Referenced by FlexFormTools\getDataStructureIdentifier().

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$fieldTcaFull TCA of the field in question that has type=flex set
string$tableNameThe table name of the TCA field
string$fieldNameThe field name
array$rowThe data row
Returns
array Identifier as array, see example above
Exceptions
InvalidCombinedPointerFieldException
InvalidSinglePointerFieldException
InvalidTcaException

Definition at line 407 of file FlexFormTools.php.

References GeneralUtility\deprecationLog(), and GeneralUtility\trimExplode().

Referenced by FlexFormTools\getDataStructureIdentifier().

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$identifierString to find the data structure location
Returns
array Parsed and normalized data structure
Exceptions
InvalidIdentifierException

Definition at line 566 of file FlexFormTools.php.

References $GLOBALS, GeneralUtility\getFileAbsFileName(), GeneralUtility\makeInstance(), and GeneralUtility\xml2array().

Referenced by FlexFormTools\traverseFlexFormXMLData().

setArrayValueByPath (   $pathArray,
$array,
  $value 
)

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

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

Definition at line 951 of file FlexFormTools.php.

traverseFlexFormXMLData (   $table,
  $field,
  $row,
  $callBackObj,
  $callBackMethod_value 
)

Handler for Flex Forms

Parameters
string$tableThe table name of the record
string$fieldThe field name of the flexform field to work on
array$rowThe record data array
object$callBackObjObject in which the call back function is located
string$callBackMethod_valueMethod 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 766 of file FlexFormTools.php.

References FlexFormTools\$callBackObj, $GLOBALS, FlexFormTools\getDataStructureIdentifier(), FlexFormTools\parseDataStructureByIdentifier(), FlexFormTools\traverseFlexFormXMLData_recurse(), and GeneralUtility\xml2array().

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$PAAdditional parameters passed.
string$pathTelling the "path" to the element in the flexform XML
Returns
array

Definition at line 808 of file FlexFormTools.php.

References FlexFormTools\executeCallBackMethod().

Referenced by FlexFormTools\traverseFlexFormXMLData().

Member Data Documentation

$callBackObj = null

Definition at line 69 of file FlexFormTools.php.

Referenced by FlexFormTools\traverseFlexFormXMLData().

Definition at line 76 of file FlexFormTools.php.

$flexArray2Xml_options
Initial value:
= [
'parentTagMap' => [
'data' => 'sheet'

Definition at line 50 of file FlexFormTools.php.

$reNumberIndexesOfSectionData = false

Definition at line 42 of file FlexFormTools.php.