[TYPO3-english] tt_content.pi_flexform reading, modiying, writing

bernd wilke t3ng at bernd-wilke.net
Thu May 28 13:49:42 CEST 2015


Am 12.05.15 um 11:35 schrieb bernd wilke:
> Am 12.05.15 um 11:19 schrieb Jigal van Hemert:
>> Hi,
>>
>> On 12/05/2015 09:51, bernd wilke wrote:
>>> due to development we have a lot of content elements (CE) with an
>>> out-of-date structure in the pi_flexform.
>>> I have to update the data to the current datastructure, but have no clue
>>> how to read, modify and write back the structure in
>>> tt_content.pi_flexform.
>>>
>>> I found a lot of tips, but every combination of functions I use:
>>> I never get back the same XML-structure.
>>>
>>> here is an example for the nearest. the endresult has nearly the same
>>> number of nodes on each level, but the tags have very differnt names and
>>> attributes:
>>>
>>> $decodeFlexFormArray =
>>> \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($record['pi_flexform']);
>>>
>>>
>>
>> That's a good start. If you look at the flexform definition the "index"
>> attributes define the tag name in the resulting array (numeric "index"
>> attribute value indicates that it's a repeated block with numeric array
>> keys)
>>
>> After you change the array you can simply let DataHandler (aka TCEmain)
>> take care of storing it again. No need to transform it back to XML at
>> all!
>>
>
> There is a way to store arrays as xml to tt_content.pi_flexform?
>
> is there any documentation to this?

I still have not found any documentation but the following does work (6.2):

get the content from field pi_flexform and change it into an array with 
xml2array().

then I could alter the array.

the last step "writing back" is easy (if you know).
having the data-array as subcontent from pi_flexform you can save the 
data with TCEmain/Datahandler. the subarray is changed automagically 
into the xml.
be aware: the values are added to the existing xml-structure.
a cleaning is possible with two updates:
1. empty pi_flexform with an empty string
2. add your 'new' structure to the empty field.

bernd
-- 
http://www.pi-phi.de/cheatsheet.html


More information about the TYPO3-english mailing list