[TYPO3-dev] Problem with FlexFrom field of type select SOLVED with itemsProcFunc function

Stephen Bungert stephenbungert at yahoo.de
Tue Sep 27 13:07:58 CEST 2011


I managed to fix this be using an itemsProcFunc on the ff select field.

Here is my function in case anyone else needs to do something similar:

Still I believe this is a bug because the righhand part of the select field 
shows the items ok, and their ids are saved in the db when the CE is saved, 
surely then the left hand part that shows the selected elements should also 
be able to show all selected record titles.

<?php
 /***************************************************************
 *  Copyright notice
 *
 *  (c) 2011 Stephen Bungert <stephenbungert at yahoo.de>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

 /**
 * [CLASS/FUNCTION INDEX of SCRIPT]
 *
 *
 *
 *   45: class tx_sbportfolio_displayModeHookProcessor
 *   52:     function tx_addDisplayModeOptions($displayModeConfig)
 *
 * TOTAL FUNCTIONS: 1
 * (This index is automatically created/updated by the extension 
"extdeveval")
 *
 */

 /**
  * Class 'tx_sbportfolio_ffcategories' for the 'sb_portfolio' extension.
  *
  * @author Stephen Bungert <stephenbungert at yahoo.de>
  * @package TYPO3
  * @subpackage tx_sbportfolio
  */
 class tx_sbportfolio_ffcategories {
 /**
  * The left part of the category field in sb_portfolios tt_content FF can 
contain values that are stored in the page TSConfig reference: 
"TCEFORM.tt_content.pi_flexform.PAGE_TSCONFIG_IDLIST"
  * They are saved ok in the database, and the righthand part of the select 
fields shows them ok too, but on rendering the selected field input (the 
left part of the select field) those items with pids set in 
###PAGE_TSCONFIG_IDLIST### are not shown.
  * This fixes the problem. Problem was caused by the property $field being 
empty when passed to selectAddForeign() in class.t3lib_transferdata.php
  *
  * @param array  $PA: field setup & config data
  * @return array  $fobj: parent object
  */
  function tx_addCategoryItems(&$PA, $fobj) {
   $objectClass = '';

   if (is_object($fobj)) {
    $objectClass = get_class($fobj);
   }

   if ($objectClass == 't3lib_transferData') { // Only need to get record 
titles for the left hand field (the selected records)
    if ($PA['config']['foreign_table']) {
     $piFfData = t3lib_div::xml2array($PA['row']['pi_flexform']);

     if (is_array($piFfData) && !empty($piFfData)) {
      $selectedElements = '';

      if 
(isset($piFfData['data']['sItemSelection']['lDEF']['category']['vDEF'])) {
       $selectedElements = 
$piFfData['data']['sItemSelection']['lDEF']['category']['vDEF'];
       $selectedElements = t3lib_div::trimExplode(',', $selectedElements, 
true);

       $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig('tt_content', 
$PA['row']);

       $selectedElementTitles = $fobj->selectAddForeign('', 
$selectedElements, array('config' => $PA['config']), 'pi_flexform', 
$TSconfig, $PA['row'], $PA['table']);

       if (is_array($selectedElementTitles) && 
!empty($selectedElementTitles)) {
        $tempArray = array();

        foreach ($selectedElementTitles as $key => $value) {
         $selData = t3lib_div::trimExplode('|', $value, true);
         $selData[1] = rawurldecode($selData[1]);
         $tempArray[] = array($selData[1], $selData[0]);
        }

        $PA['items'] = $tempArray;
       }
      }
     }
    }
   }
  }

 }



 // Add XCLASS
 if (defined('TYPO3_MODE') && 
$TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sb_portfolio/class.tx_sbportfolio_ffcategories.php']) 
{
  include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/sb_portfolio/class.tx_sbportfolio_ffcategories.php']);
 }
?> 





More information about the TYPO3-dev mailing list