Flexforms

Einige Information ist hier zu finden: wiki.typo3.org/index.php/Extension_Development%2C_using_Flexforms

Konfiguration

Hinzufügen zu ext_tables.php

// display tt_content flexform-field
$TCA['tt_content']['types']['list']['subtypes_addlist'][$_EXTKEY.'_pi1']
    ='pi_flexform';

// load configuration
t3lib_extMgm::addPiFlexFormValue($_EXTKEY.'_pi1', 'FILE:EXT:rsys_fields/flexform_ds.xml');

 flexform_ds.xml

<T3DataStructure>

  <sheets>

    <sDEF>
      <ROOT>

        <TCEforms>
          <sheetTitle>LLL:EXT:rsys_fields/locallang_db.xml:
            tt_content.pi_flexform.sheet_general</sheetTitle>
        </TCEforms>

        <type>array</type>

        <el>
          <enable>
            <TCEforms>
                <label>LLL:EXT:rsys_fields/locallang_db.xml:
                   tt_content.
tt_content.pi_flexform.enable</label>
                <config>
                    <type>check</type>
                </config>

            </TCEforms>
          </enable>
          <show_all>
            <TCEforms>
                 <label>LLL:EXT:rsys_fields/locallang_db.xml:
                   tt_content.pi_flexform.show_all</label>
                <config>
                    <type>check</type>
                </config>

            </TCEforms>
          </show_all>
        </el>

      </ROOT>

    </sDEF>

    <s_welcome>
      <ROOT>
        <TCEforms>
            <sheetTitle>LLL:EXT:rsys_fields/locallang_db.xml:
              tt_content.pi_flexform.sheet_welcome</sheetTitle>
        </TCEforms>
        <type>array</type>
        <el>
          <header>
            <TCEforms>
                <label>LLL:EXT:rsys_fields/locallang_db.xml:
                  tt_content.pi_flexform.header</label>
                <config>
                    <type>input</type>
                    <size>30</size>
                </config>
            </TCEforms>
          </header>
          <message>
            <TCEforms>
                <label>LLL:EXT:rsys_fields/locallang_db.xml:
                  tt_content.pi_flexform.message</label>
                <config>
                    <type>text</type>
                    <cols>30</cols>
                    <rows>5</rows>
                </config>
            </TCEforms>
          </message>         
        </el>
      </ROOT>
    </s_welcome>
 
  </sheets>
</T3DataStructure>

Language locallang_db.xml

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3locallang>
  <meta type="array">
    <type>database</type>
    <description>Language labels for database tables/fields
                 belonging to extension 'rsys_fields'</description>
  </meta>
  <data type="array">
    <languageKey index="default" type="array">
      <label index=
         "tt_content.pi_flexform.sheet_general">Properties</label>
      <label index=
         "tt_content.pi_flexform.show_all">Show all</label>
     </languageKey>
     <languageKey index="de" type="array">
       <label index=
          "tt_content.pi_flexform.sheet_general">Einst.</label>
       <label index=
          "tt_content.pi_flexform.show_all">Alle anzeigen</label>
     </languageKey>
   </data>
</T3locallang>

Zugriff

Einfacher Zugriff

$this->pi_initPIflexForm(); // Init and get the flexform data of the plugin

$this->pi_getFFvalue($this->cObj->data['pi_flexform'], $key, $sheet);
// e.g $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'enable', 'sDEF');

 $this->pi_initPIflexForm(); // Init and get the flexform data of the plugin
 $this->lConf = array(); // Setup our storage array...
 // Assign the flexform data to a local variable for easier access
 $piFlexForm = $this->cObj->data['pi_flexform'];
 
// Traverse the entire array based on the language...
// and assign each configuration option to $this->lConf array...
 foreach ( $piFlexForm['data'] as $sheet => $data )
  foreach ( $data as $lang => $value )
   foreach ( $value as $key => $val )
    $this->lConf[$key] = $this->pi_getFFvalue($piFlexForm, $key, $sheet);
}

Erstellt: 07/2010| Geändert: 10/2015

Select

Um Daten aus einer Tabelle in der Flexform zu verwenden folgendes in das XML:

<el>
<show_category>
  <TCEforms>
    <label>LLL:EXT:rsys_fields/locallang_db.xml:tt_content.pi_flexform.show_category</label>
    <config>
      <type>select</type>
      <itemsProcFunc>tx_rsysfields_addFieldsToFlexForm->addFields</itemsProcFunc>
    </config>
  </TCEforms>
</show_category>
</el>

In ext_tables:

// Flexform dynamic function
include_once(t3lib_extMgm::extPath($_EXTKEY).'pi1/class.tx_rsysfields_addFieldsToFlexForm.php');

In tx_rsysfields_addFieldsToFlexForm:

class tx_rsysfields_addFieldsToFlexForm {

  /**
   * Adding category entries to Flexform
   *
   * @param  array    $config: the config array
   * @return  array    items for select type in flexform XML
   * @todo Multilanguage support needs to be implemented
   */
  function addFields($config) {
    $optionList = array ();

    // Execute query
    $table = 'tx_rsysfields_category';
    $enableFields = ' NOT hidden AND NOT deleted AND sys_language_uid = 0';
    $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, $enableFields, '', 'category DESC');

    // Fill array with options
    while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
      $optionList[] = array (
        0 => $row['category'],
        1 => $row['uid']
      );
    }
    // merge results and return
    $config['items'] = array_merge($config['items'], $optionList);
    return $config;
  }
}

Hardcodiert

<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:rsys_fields/locallang_db.xml:tx_rsysfields_menu.titletext</numIndex>
    <numIndex index="1">titletext</numIndex>
    </numIndex>
   <numIndex index="2" type="array">
    <numIndex index="0">LLL:EXT:rsys_fields/locallang_db.xml:tx_rsysfields_menu.category</numIndex>
    <numIndex index="1">category</numIndex>
   </numIndex>
   <numIndex index="3" type="array">
    <numIndex index="0">LLL:EXT:rsys_fields/locallang_db.xml:tx_rsysfields_menu.product_description</numIndex>
    <numIndex index="1">product_description</numIndex>
   </numIndex>
  </items>
</config>

Erstellt: 07/2010| Geändert: 10/2015