Siva
Siva

Reputation: 509

itemsProcFunc and selected items in TYPO3 6.2

I'm writing an extension which is configured via FlexForms. One element of the FlexForm is of type 'select', with maxitems > 1. I use itemsProcFunc to call an external class method modifying the 'items' array.

This works fine so far, but when I try to save the plugin options in BE, the entries under 'Selected:' vanish. However, the selected values are stored correctly. See below for my flexform configuration .

<settings.flexuserList>
                    <TCEforms>
                      <label>Sektionen</label>
                      <config>
                        <type>select</type>
                        <itemsProcFunc>tx_hevpersons_sections->dogetSectionInfo1</itemsProcFunc>
                        <maxitems>10000</maxitems>
                        <size>10</size>
                      </config>
                    </TCEforms>
                  </settings.flexuserList>


public function dogetSectionInfo1($params, $conf)      
        {
                print_r($params['row']['pi_flexform']);
                $flexform                       = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($params['row']['pi_flexform']);
                $grp                            = $flexform['data']['sDEF']['lDEF']['settings.flexroleList']['vDEF'];
                $flexcantonval                  = $flexform['data']['sDEF']['lDEF']['settings.flexcanton']['vDEF'];
                $flexsectionList                = $flexform['data']['sDEF']['lDEF']['settings.flexsectionList']['vDEF'];
                $flexuserList                   = $flexform['data']['sDEF']['lDEF']['settings.flexuserList']['vDEF'];
                f( strstr( $grp , "|" ) ){
                        $string =  explode(",",$grp);
                        foreach ($string as $key => $value) {
                                $array = explode('|',$value);
                                $nearay[$key] = $array[0];
                        }
                }



                if( count($nearay) ){
                        foreach ($nearay as $key => $value) {
                                $usergroupFind[$key] = 'FIND_IN_SET("'.$value.'",usergroup)';
                        }
                        $string = ' AND  '.implode(' OR ', $usergroupFind) . '  ';
                }

if( !empty($string) ){
                      $GLOBALS['TYPO3_DB']->store_lastBuiltQuery = 1;
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery("uid, name ", 'fe_users', 'deleted=0 AND disable=0 '.$string );

                        while($entry = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))
                        {
                                $params['items'][count($params['items'])] = array(trim($entry['name'] ), $entry['uid']);
                        }
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);   
                }
                return $params;
}

When a printed flexfrom , I got 2 xml records in which one has comma seperated values stored inside the xml while the other has empty values . Can some one help me with this ?

Upvotes: 0

Views: 2715

Answers (1)

Ghanshyam Gohel
Ghanshyam Gohel

Reputation: 1274

I think you should return config instead of params.

One of my working example, might be your helps:
TYPO3 v7.6.2

-FlexForm settings

<settings.eventID>
    <TCEforms>
        <label>Available Event</label>
        <config>
            <type>select</type>
            <size>1</size>
            <minitems>0</minitems>
            <maxitems>1</maxitems>
            <itemsProcFunc>VENDOR\EXT\Controller\ControllerName->flexFormsEventsListItems</itemsProcFunc>
            <items type="array"></items>
        </config>
    </TCEforms>
</settings.eventID>

-Action

public function flexFormsEventsListItems($config){
    $formsRepository = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('fields', 
                                'table_name', 
                                'WHERE clause', '', '', '', '');

    $formsData = array(
        'Events' => $formsRepository,
    );

    // create option list
    $optionList = array();
    foreach($formsRepository as $key=>$item){ 
        $label = $item['title'];
        $value = $item['uid'];

        $optionList[] = array(0 => $label, 1 => $value);
    }

    // return config
    $config['items'] = array_merge($config['items'], $optionList);
    return $config;
}

Upvotes: 2

Related Questions