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

bernd wilke t3ng at bernd-wilke.net
Tue May 12 09:51:31 CEST 2015


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

$encodeAgain = 
\TYPO3\CMS\Core\Utility\GeneralUtility::array2xml_cs($decodeFlexFormArray);


IN ($record['pi_flexform']):

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<T3FlexForms>
     <data>
         <sheet index="options">
             <language index="lDEF">
                 <field index="headline">
                     <value index="vDEF">H1 black, TXT, IMG 7 right 
noflow, Link</value>
                 </field>
                 <field index="htmlelement">
                     <value index="vDEF">H1</value>
                 </field>
                 <field index="hlColor">
                     <value index="vDEF">black</value>
                 </field>
                 <field index="text">
                     <value index="vDEF">&lt;div 
class="blindtext"&gt;Das habgefüh auwen ein ger auplanter wein 
inetrotter Zeitten wein, nichtstochall' inn Dacht seicht and Seeiney ent 
jedern nichtetentlin umt. Gestückt und in Hanzei, daushasse dunder.
:
:

OUT ($encodeAgain):

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<phparray>
	<data type="array">
		<options type="array">
			<lDEF type="array">
				<headline type="array">
					<vDEF>H1 black, TXT, IMG 7 right noflow, Link</vDEF>
				</headline>
				<htmlelement type="array">
					<vDEF>H1</vDEF>
				</htmlelement>
				<hlColor type="array">
					<vDEF>black</vDEF>
				</hlColor>
				<text type="array">
					<vDEF>&lt;div class=&quot;blindtext&quot;&gt;Das habgefüh auwen ein 
ger auplanter wein inetrotter Zeitten wein, nichtstochall' inn Dacht 
seicht and Seeiney ent jedern nichtetentlin umt. Gestückt und in Hanzei, 
daushasse dunder.
:
:

background story:

we started with fluid_content 3.0 and defined a series of own CEs.
with time the need for more options led to the restructuring of the 
input fields into multiple tabs. resulting in the same restructure in 
the xml.
with the early versions of fluid_content there was no problem as the 
fields were accessed independently from sheet.
after an update to fluid_content 4.0 the FE rendering (and BE preview) 
still work, but editing is not possible any more as the inout-fields are 
initialized with the fields from the exact structure (which is not 
available with old records)
if I would update fluid_content to newer versions (4.1) also the FE 
rendering stops working, which breaks our site.



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


More information about the TYPO3-english mailing list