Typo3 Extensions mit FlexForms: Unterschied zwischen den Versionen
| Zeile 17: | Zeile 17: | ||
$TCA['tt_content']['types']['list']['subtypes_addlist'][$_EXTKEY.'_pi1']='pi_flexform'; | $TCA['tt_content']['types']['list']['subtypes_addlist'][$_EXTKEY.'_pi1']='pi_flexform'; | ||
# Nun die Datei angeben in der das Flexform-Schema definiert ist... | # Nun die Datei angeben in der das Flexform-Schema definiert ist... | ||
| − | t3lib_extMgm::addPiFlexFormValue($_EXTKEY.' | + | t3lib_extMgm::addPiFlexFormValue($_EXTKEY.'_pi1','FILE:EXT:'.$_EXTKEY.'/flexform_ds.xml'); |
# Plugin aktivieren-dies sorgt dafür, dass das Plugin im Backend überhaupt ausgewählt werden kann (legt der EM automatisch an) | # Plugin aktivieren-dies sorgt dafür, dass das Plugin im Backend überhaupt ausgewählt werden kann (legt der EM automatisch an) | ||
Version vom 25. Oktober 2007, 11:12 Uhr
Benötigte Dateien
Man braucht:
- Änderungen in ext_tables.php
- Die Datei flexform_ds.xml. In dieser befindet sich der XML code den Typo3 nutzt um das Flexform zu generieren.
- In der Datei wird im Abschnitt Label auf die Datei: locallang_db.xml verwiesen. In dieser wiederum werden die anderen Sprachen definiert.
ext_tables.php: FlexForm einblenden
Beispiel ext_tables.php (Ausschnitt):
# Vor jeder Änderung im TCA Bereich im Frontend muß er auch geladen sein...(von EM Manager schon angelegt)
t3lib_div::loadTCA('tt_content');
# Wir nutzen FlexForms - deshalb blenden wir die Standard-Felder layout, select_key pages und recursive aus...
$TCA['tt_content']['types']['list']['subtypes_excludelist'][$_EXTKEY.'_pi1']='layout,select_key,pages,recursive';
# Dafür blenden wir das tt_content-Felod pi_flexform ein
$TCA['tt_content']['types']['list']['subtypes_addlist'][$_EXTKEY.'_pi1']='pi_flexform';
# Nun die Datei angeben in der das Flexform-Schema definiert ist...
t3lib_extMgm::addPiFlexFormValue($_EXTKEY.'_pi1','FILE:EXT:'.$_EXTKEY.'/flexform_ds.xml');
# Plugin aktivieren-dies sorgt dafür, dass das Plugin im Backend überhaupt ausgewählt werden kann (legt der EM automatisch an)
t3lib_extMgm::addPlugin(array('LLL:EXT:hfwupersonal/locallang_db.xml:tt_content.list_type_pi1', $_EXTKEY.'_pi1'),'list_type');
Definition der Flexform Felder (flexform_ds.xml)
Beispiel flexform_ds.xml
Hinweis: Der Name der XML Datei kann auch anders gewählt werden. Dieser Name ist jedoch der Standardname.
<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
<T3FlexForms>
<data type="array">
<sDEF type="array">
<lDEF type="array">
<inputName type="array">
<vDEF>Beispielwort</vDEF>
</inputName>
<inputTransformation type="array">
<vDEF>lowercase</vDEF>
</inputTransformation>
</lDEF>
</sDEF>
</data>
</T3FlexForms>
Innerhalb von sheets stehen die Tabs, sDEF ist das aktuelle Sheet.
Flexforms gestalten
Ein Flexform hat folgende Grundstruktur:
<T3DataStructure>
<meta>
<langDisable>1</langDisable>
</meta>
<ROOT>
[...formatspezifisches Element ... ]
<type>array</type>
<el>
<freierElementName1>
[ ... formatspezifisches Element ... ]
</freierElementName1>
<freierElementName2>
[ ... formatspezifisches Element ... ]
</freierElementName2>
</el>
</ROOT>
</T3DataStructure>
Ein Beispiel mit allerlei Eingabefeldern könnte wie folgt aussehen. In diesem Beispiel wird für die Namen der Felder auf eine locallang_tca.php verwiesen. Man könnte die Namen der Labels aber auch einfach direkt reinschreiben.
Einleitender Code
<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?> <T3DataStructure> <sheets>
Das erste Sheet
Hier beginnt das erste Sheet man stellt vor den xml bezeichner gewöhnlich ein s für sheet. Das erste formspezifische Element ist der Titel des Tabs, dann kommt ein Array und das Einleitende el Tag indem alle Elemente des Tabs gespeichert sind.
<sInputs>
<ROOT>
<TCEforms>
<sheetTitle>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.sheetInputs</sheetTitle>
</TCEforms>
<type>array</type>
<el>
Eingabefeld
<exampleString> <TCEforms> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleString.label</label> <config> <type>input</type> <size>24</size> <max>48</max> <eval>trim</eval> </config> </TCEforms> </exampleString>
Datumsfeld
<exampleDate> <TCEforms> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleDate.label</label> <config> <type>input</type> <size>8</size> <eval>date</eval> <max>20</max> <checkbox>1</checkbox> </config> </TCEforms> </exampleDate>
Ein Textfeld
<exampleArea> <TCEforms> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleArea.label</label> <config> <type>text</type> <cols>24</cols> <rows>3</rows> </config> </TCEforms> </exampleArea>
Ein Textfeld mit abgeschaltetem Zeilenumbruch für Code
<exampleCode> <TCEforms> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleCode.label</label> <config> <type>text</type> <cols>35</cols> <rows>8</rows> <wrap>off</wrap> </config> </TCEforms> </exampleCode>
Das erste Blatt ist fertig
</el>
</ROOT>
</sInputs>
RTE
Das nächste Blatt enthält einen RTE...
<sRTE>
<ROOT>
<TCEforms>
<sheetTitle>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.sheetRTE</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<exampleRTE>
<TCEforms>
<label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleRTE.label</label>
<config>
<type>text</type>
<cols>52</cols>
<rows>5</rows>
</config>
<defaultExtras>richtext[*]:rte_transform[mode=ts_css]</defaultExtras>
</TCEforms>
</exampleRTE>
</el>
</ROOT>
</sRTE>
Auswahlfelder
Das nächste Blatt enthält Beispiele für Auswahlfelder...
<sSelections>
<ROOT>
<TCEforms>
<sheetTitle>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.sheetSelections</sheetTitle>
</TCEforms>
<type>array</type>
<el>
Ein einfaches Select Feld
Zu beachten ist hierbei, daß der Tag numIndex index="0" den Namen(oder das Label) des Optionspunktes enthält, index="1" dagegen den key, also den später nutzbaren Wert.
<exampleSelection> <TCEforms> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleSelection.label</label> <config> <type>select</type> <items type="array"> <numIndex index="0" type="array"> <numIndex index="0">LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleSelection.label1</numIndex> <numIndex index="1">key1</numIndex> </numIndex> <numIndex index="1" type="array"> <numIndex index="0">LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleSelection.label2</numIndex> <numIndex index="1">key2</numIndex> </numIndex> <numIndex index="3" type="array"> <numIndex index="0">LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleSelection.label3</numIndex> <numIndex index="1">key3</numIndex> </numIndex> </items> </config> </TCEforms> </exampleSelection>
Mehrfachauswahl
<exampleMultiselection> <TCEforms> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleMultiselection.label</label> <config> <type>select</type> <items type="array"> <numIndex index="0" type="array"> <numIndex index="0">LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleMultiselection.label1</numIndex> <numIndex index="1">key1</numIndex> </numIndex> <numIndex index="1" type="array"> <numIndex index="0">LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleMultiselection.label2</numIndex> <numIndex index="1">key2</numIndex> </numIndex> <numIndex index="3" type="array"> <numIndex index="0">LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleMultiselection.label3</numIndex> <numIndex index="1">key3</numIndex> </numIndex> </items> <maxitems>3</maxitems> <size>3</size> <multiple>1</multiple> <selectedListStyle>width:150px</selectedListStyle> <itemListStyle>width:150px</itemListStyle> </config> </TCEforms> </exampleMultiselection>
Ein Seitenbrowser
<examplePagebrowser> <TCEforms> <exclude>1</exclude> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.examplePagebrowser.label</label> <config> <type>group</type> <internal_type>db</internal_type> <allowed>pages</allowed> <size>3</size> <maxitems>22</maxitems> <minitems>0</minitems> <show_thumbs>1</show_thumbs> </config> </TCEforms> </examplePagebrowser>
Ein Dateibrowser
<exampleFilebrowser> <TCEforms> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleFilebrowser.label</label> <config> <type>group</type> <internal_type>file</internal_type> <allowed>tmpl,html</allowed> <max_size>100</max_size> <uploadfolder>uploads/</uploadfolder> <maxitems>1</maxitems> <size>1</size> <selectedListStyle>Width:180px</selectedListStyle> </config> </TCEforms> </exampleFilebrowser>
Eine Checkbox
<exampleCheckbox> <TCEforms> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleCheckbox.label</label> <config> <type>check</type> </config> </TCEforms> </exampleCheckbox>
Radio Buttons
<exampleRadio> <TCEforms> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleRadio.label</label> <config> <type>radio</type> <items type="array"> <numIndex index="0" type="array"> <numIndex index="0">LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleRadio.label1</numIndex> <numIndex index="1">key1</numIndex> </numIndex> <numIndex index="1" type="array"> <numIndex index="0">LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleRadio.label2</numIndex> <numIndex index="1">key2</numIndex> </numIndex> <numIndex index="3" type="array"> <numIndex index="0">LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleRadio.label3</numIndex> <numIndex index="1">key3</numIndex> </numIndex> </items> </config> </TCEforms> </exampleRadio>
Ende des Sheets
</el>
</ROOT>
</sSelections>
Auswahlfelder können Ihre Werte auch dynamisch aus der Datenbank beziehen, darum gehts im nächsten Sheet
<sDynamics>
<ROOT>
<TCEforms>
<sheetTitle>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.sheetDynamics</sheetTitle>
</TCEforms>
<type>array</type>
<el>
Ein dynamisches Select Feld
mit Werten aus der Tabelle static_template
<exampleQuery> <TCEforms> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleQuery.label</label> <config> <type>select</type> <items> <numIndex index="0"> <numIndex index="0">--</numIndex> <numIndex index="1">0</numIndex> </numIndex> </items> <foreign_table>static_template</foreign_table> <foreign_table_where> AND static_template.uid < 30 </foreign_table_where> <size>1</size> <minitems>0</minitems> <maxitems>1</maxitems> </config> </TCEforms> </exampleQuery>
Eine Funktion kann ebenfalls genutzt werden um die WErte bereitzustellen
<exampleFunction> <TCEforms> <label>LLL:EXT:sb_flexamples/locallang_tca.php:sb_flexamples.pi_flexform.exampleFunction.label</label> <config> <type>select</type> <items> <numIndex index="0"> <numIndex index="0">--</numIndex> <numIndex index="1">0</numIndex> </numIndex> </items> <itemsProcFunc>tx_sbflexamples_itemFunctions->exampleFunction</itemsProcFunc> </config> </TCEforms> </exampleFunction>
XML-Struktur beenden
Das letzte Sheet fertigstellen...
</el>
</ROOT>
</sDynamics>
Die komplette Struktur beenden
</sheets> </T3DataStructure>
Labels übersetzen - Sprachdatei
Der Vollständigkeit halber ein Auszug aus der locallang_tca.php in der die Sprachlabels definiert werden:
<?php
$LOCAL_LANG = Array ( 'default' => Array ( ... 'hfwupersonal.pi_flexform.sheetSelections' => 'Selections', 'hfwupersonal.pi_flexform.sheetDynamics' => 'Dynamic Selections', 'hfwupersonal.pi_flexform.exampleDate.label' => 'Date', ... ), 'de' => Array ( ... 'hfwupersonal.pi_flexform.sheetSelections' => 'Statische Auswahlfelder', 'hfwupersonal.pi_flexform.sheetDynamics' => 'Dynamische Auswahlfelder', 'hfwupersonal.pi_flexform.exampleDate.label' => 'Datum', ... ), ); ?>
Auf Flexform-Daten zugreifen
Um die Daten aus dem Flexform zu verarbeiten nutzen wir Funktionen der tslib_pibase. Die Daten befinden sich als XML-String in
$this->cObj->data['pi_flexform'] Um den Zugriff zu vereinfachen gibt es eine Funktion die den Inhalt in ein Array rendert:
$this->pi_initPIflexForm();
jetzt steht ein Array in $this->cObj->data['pi_flexform'] zur Verfügung. Darauf könnte man jetzt schon gut zugreifen. Besonders leicht geht es aber mit der Funktion:
function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF,$lang='lDEF',$value='vDEF');
Beispiel:
$myName = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'inputName');
In diesem Fall wäre $sheet,$lang und $value mit den Defaultwerten benannt (siehe XML-Beispiel), deshalb müssen Sie nicht übergeben werden.