rtgx

Použitie flexforms 1

Postup pre vytvorenie konfiguračného XML súboru

Pri vkladaní pluginu do obsahu často potrebuje nastaviť viac údajov, ako tie, ktoré máme k dispozícii. Jednou možnosťou je rozšíriť tabuľku tt_content o nové položky a upraviť pole TCA. Oveľa elegantnejšie riešenie však ponúkajú hojne používané flexforms.

Napríklad takýto výsledok pri editovaní nášho pluginu v backende potrebujeme dostať:

Prvá záložka
Prvá záložka
Druhá záložka
Druhá záložka

Dosiahneme to konfiguračným súborom (flexform.xml):

<T3DataStructure>
<meta>
<langDisable>1</langDisable>
</meta>
<sheets>

<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>LLL:EXT:extensionname/locallang_db.php:tt_content.pi_flexform.sheet_general</sheetTitle>
</TCEforms>
<type>array</type>
<el>

<what_to_display>
<TCEforms>
<label>LLL:EXT:extensionname/locallang_db.php:tt_content.pi_flexform.type</label>
<config>
<type>select</type>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0"></numIndex>
<numIndex index="1"></numIndex>
</numIndex>
<numIndex index="1" type="array">
<numIndex index="0">LIST</numIndex>
<numIndex index="1">LIST</numIndex>
</numIndex>
<numIndex index="2" type="array">
<numIndex index="0">SINGLE</numIndex>
<numIndex index="1">SINGLE</numIndex>
</numIndex>
<numIndex index="3" type="array">
<numIndex index="0">PODCAST</numIndex>
<numIndex index="1">PODCAST</numIndex>
</numIndex>
<numIndex index="4" type="array">
<numIndex index="0">RSS</numIndex>
<numIndex index="1">RSS</numIndex>
</numIndex>
<numIndex index="5" type="array">
<numIndex index="0">PODCAST LINK</numIndex>
<numIndex index="1">PODCAST_LINK</numIndex>
</numIndex>
<numIndex index="6" type="array">
<numIndex index="0">RSS LINK</numIndex>
<numIndex index="1">RSS_LINK</numIndex>
</numIndex>
</items>
<minitems>0</minitems>
<maxitems>1</maxitems>
<size>1</size>
</config>
</TCEforms>
</what_to_display>

<pages>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:lang/locallang_general.php:LGL.startingpoint</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>
</pages>

<recursive>
<TCEforms>
<label>LLL:EXT:lang/locallang_general.php:LGL.recursive</label>
<config>
<type>select</type>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0"></numIndex>
<numIndex index="1"></numIndex>
</numIndex>
<numIndex index="1" type="array">
<numIndex index="0">LLL:EXT:cms/locallang_ttc.php:recursive.I.1</numIndex>
<numIndex index="1">1</numIndex>
</numIndex>
<numIndex index="2" type="array">
<numIndex index="0">LLL:EXT:cms/locallang_ttc.php:recursive.I.2</numIndex>
<numIndex index="1">2</numIndex>
</numIndex>
<numIndex index="3" type="array">
<numIndex index="0">LLL:EXT:cms/locallang_ttc.php:recursive.I.3</numIndex>
<numIndex index="1">3</numIndex>
</numIndex>
<numIndex index="4" type="array">
<numIndex index="0">LLL:EXT:cms/locallang_ttc.php:recursive.I.4</numIndex>
<numIndex index="1">4</numIndex>
</numIndex>
<numIndex index="5" type="array">
<numIndex index="0">LLL:EXT:cms/locallang_ttc.php:recursive.I.5</numIndex>
<numIndex index="1">250</numIndex>
</numIndex>
</items>
<minitems>0</minitems>
<maxitems>1</maxitems>
<size>1</size>
</config>
</TCEforms>
</recursive>

</el>
</ROOT>
</sDEF>

<podcast>
<ROOT>
<TCEforms>
<sheetTitle>LLL:EXT:extensionname/locallang_db.php:tt_content.pi_flexform.sheet_podcast</sheetTitle>
</TCEforms>
<type>array</type>
<el>

<title>
<TCEforms>
<label>LLL:EXT:extensionname/locallang_db.php:tt_content.pi_flexform.title</label>
<config>
<type>input</type>
<size>40</size>
</config>
</TCEforms>
</title>

<description>
<TCEforms>
<label>LLL:EXT:extensionname/locallang_db.php:tt_content.pi_flexform.description</label>
<config>
<type>text</type>
<cols>40</cols>
<rows>2</rows>
</config>
</TCEforms>
</description>

<copyright>
<TCEforms>
<label>LLL:EXT:extensionname/locallang_db.php:tt_content.pi_flexform.copyright</label>
<config>
<type>input</type>
<size>30</size>
</config>
</TCEforms>
</copyright>

</el>
</ROOT>
</podcast>

</sheets>
</T3DataStructure>

Aby tento súbor náš modul vedel použiť, nastavíme v súbore ext_tables.php tieto riadky:

// You add pi_flexform to be renderd when your plugin is shown
$TCA['tt_content']['types']['list']['subtypes_addlist'][$_EXTKEY.'_pi1']='pi_flexform';
// NOTE: Be sure to change sampleflex to the correct directory name of your extension!
t3lib_extMgm::addPiFlexFormValue($_EXTKEY.'_pi1', 'FILE:EXT:extensionname/flexform.xml');

Samozrejme nesmieme zabudnúť jazykové preklady vložiť do súboru locallang_db.php nášho modulu, inak budeme mať prázdne názvy položiek formulára. Skrátený príklad:

...
<languageKey index="default" type="array">
<label index="tt_content.pi_flexform.sheet_general">Settings</label>
<label index="tt_content.pi_flexform.type">View</label>
<label index="tt_content.pi_flexform.sheet_podcast">Special RSS</label>
<label index="tt_content.pi_flexform.title">Title</label>
...
</languageKey>
...

Typy vstupných polí pre flexforms 2

Input
<label>LLL:EXT:extensionname/locallang_db.php:tt_content.pi_flexform.input</label>
<config>
<type>input</type>
<size>40</size>
</config>
Textarea
<label>LLL:EXT:extensionname/locallang_db.php:tt_content.pi_flexform.textarea</label>
<config>
<type>text</type>
<cols>40</cols>
<rows>2</rows>
</config>
Checkbox

Defaultne bude zaškrtnutý.

<label>LLL:EXT:extensionname/locallang_db.php:tt_content.pi_flexform.checkbox</label>
<config>
<type>check</type>
<default>1</default>
</config>
Selectbox
<label>LLL:EXT:lang/locallang_general.php:LGL.recursive</label>
<config>
<type>select</type>
<items type="array">
<numIndex index="0" type="array">
<numIndex index="0"></numIndex>
<numIndex index="1"></numIndex>
</numIndex>
<numIndex index="1" type="array">
<numIndex index="0">LLL:EXT:cms/locallang_ttc.php:recursive.I.1</numIndex>
<numIndex index="1">1</numIndex>
</numIndex>
<numIndex index="2" type="array">
<numIndex index="0">LLL:EXT:cms/locallang_ttc.php:recursive.I.2</numIndex>
<numIndex index="1">2</numIndex>
</numIndex>
...
</items>
<minitems>0</minitems>
<maxitems>1</maxitems>
<size>1</size>
</config>
File

Povolené typy súborov: tmpl, html, htm.

<label>LLL:EXT:extensionname/locallang_db.php:tt_content.pi_flexform.file</label>
<config>
<type>group</type>
<internal_type>file</internal_type>
<allowed>tmpl,html,htm</allowed>
<max_size>100</max_size>
<uploadfolder>uploads/tx_extensionname</uploadfolder>
<maxitems>1</maxitems>
<size>1</size>
<selectedListStyle>Width:180px</selectedListStyle>
</config>
Database relation

Relačná tabuľka: pages
Minimálny počet relácií: 0
Maximálny počet relácií: 22

<exclude>1</exclude>
<label>LLL:EXT:lang/locallang_general.php:LGL.startingpoint</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>
Database relation and selectbox

Relačná tabuľka: tx_extname_categories
Podmienka výberu položiek: AND tx_extname_categories.sys_language_uid IN (-1,0)
(vyberú sa len záznamy v defaultnom jazyku)

Minimálny počet relácií: 0
Maximálny počet relácií: 1

<label>LLL:EXT:extname/locallang_db.php:tt_content.pi_flexform.category_uid</label>
<config>
<type>select</type>
<foreign_table>tx_extname_categories</foreign_table>
<foreign_table_where>AND tx_extname_categories.sys_language_uid IN (-1,0)</foreign_table_where>
<items>
<numIndex index="0">
<numIndex index="0">...</numIndex>
<numIndex index="1">0</numIndex>
</numIndex>
</items>
<minitems>0</minitems>
<maxitems>1</maxitems>
<size>1</size>
</config>

Načítanie flexform dát v module

Inicializácia a načítanie XML dát:

$this->pi_initPIflexForm(); // Init FlexForm configuration for plugin
$this->pi_flexform = $this->cObj->data['pi_flexform'];

Načítanie konkrétnej hodnoty:

$code = $this->pi_getFFvalue( $this->pi_flexform, 'what_to_display', 'sDEF' );