Verwendet man auf einer Seite ein Flexform basiertes Plugin zur Darstellung besionderer Inhalte, in unserem Fall einer Smartbox, die immer in der rechten Spalte eingebunden wird, so entsteht bei komplexeren Plugins der Wunsch, einen Teil der Daten erneut einzugeben, einen anderen Teil der Daten des Flexforms jedoch rekursiv aus einem bereits eingebundenen Plugin innerhalb der Rootline auszulesen.
Zunächst der Klasse des Plugins eine weitere Variable hinzufügen:
var $rootlineFlexform = array();
Dann innerhalb der main-Methode relativ am Anfang die Flexforms initialisieren:
$this->initRootlineFlexforms('my_plugin_pi1');
Aufrufe zum Auslesen eines Flexformwertes sollten dann z.B. so geschehen:
$tabActive = $this->getFlexfromValue( 'tabActive', 'sDEF' );
Wenn in der Rootline kein PLugin mit einem Wert zum Thema gefunden wurde, so findet ein Fallback auf per TypoScript gesetzte defaults statt. Diese werden für obiges Beispiel so gesetzt:
plugin.tx_myplugin_pi1.defaultFlexValues{ tabActive = 3 }
Last but not least folgende beiden Funktionen dem Plugin hinzufügen:
/** * Initializes Flexforms of all Plugins found in Rootline * * @author Marit AG, Lina Wolf, http://blog.marit.ag * @param string $list_type: Type of the Plugin * @return null */ function initRootlineFlexforms($list_type) { $rootUidArray = array(); foreach($GLOBALS['TSFE']->tmpl->rootLine AS $value) $rootUidArray[] = $value['uid']; $rootUidList = implode(',', $rootUidArray); $table = 'tt_content'; $select = 'pid, pi_flexform'; $whereClause = ' list_type="'.$list_type.'" AND pid IN ('.$rootUidList.') '. $this->cObj->enableFields('tt_content'); $itemList = ''; $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $whereClause); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { # Keep original sorting of flexform values $key = array_search($row['pid'], $rootUidArray); $this->rootlineFlexform[$key] = t3lib_div::xml2array($row['pi_flexform'], 'T3'); } ksort($this->rootlineFlexform); $this->rootlineFlexform = array_reverse($this->rootlineFlexform); } /** * Retrieves rekursively a flexform var, Fallsback to TypoScript defaults if none found * * @author Marit AG, Lina Wolf, http://blog.marit.ag * @param string $field: Field in Flexform * @param string $sheet: Sheet in Flexform * @return a value rekursively found in the flexforms */ function getFlexfromValue($field, $sheet) { foreach($this->rootlineFlexform AS $flex) { $ret = $this->pi_getFFvalue($flex, $field, $sheet ); if($ret) return $ret; } # TypoSscript Fallback $ret = $this->cObj->stdWrap($this->conf['defaultFlexValues.'][$field],$this->conf['defaultFlexValues.'][$field.'.']); return $ret; } /** * Initializes Flexforms of all Plugins found in Rootline * * @author Marit AG, Lina Wolf * @param string $list_type: Type of the Plugin * @return null */ function initRootlineFlexforms($list_type) { $rootUidArray = array(); foreach($GLOBALS['TSFE']->tmpl->rootLine AS $value) $rootUidArray[] = $value['uid']; $rootUidList = implode(',', $rootUidArray); $table = 'tt_content'; $select = 'pid, pi_flexform'; $whereClause = ' list_type="'.$list_type.'" AND pid IN ('.$rootUidList.') '. $this->cObj->enableFields('tt_content'); $itemList = ''; $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $whereClause); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { # Keep original sorting of flexform values $key = array_search($row['pid'], $rootUidArray); $this->rootlineFlexform[$key] = t3lib_div::xml2array($row['pi_flexform'], 'T3'); } ksort($this->rootlineFlexform); $this->rootlineFlexform = array_reverse($this->rootlineFlexform); #t3lib_div::debug($this->rootlineFlexform); } /** * Retrieves rekursively a flexform var, Fallsback to TypoScript defaults if none found * * @author Marit AG, Lina Wolf * @param string $field: Field in Flexform * @param string $sheet: Sheet in Flexform * @return a value rekursively found in the flexforms */ function getFlexfromValue($field, $sheet) { foreach($this->rootlineFlexform AS $flex) { $ret = $this->pi_getFFvalue($flex, $field, $sheet ); if($ret) return $ret; } # TypoSscript Fallback $ret = $this->cObj->stdWrap($this->conf['defaultFlexValues.'][$field],$this->conf['defaultFlexValues.'][$field.'.']); return $ret; }