itemsProcFunc和TYPO3 6.2中的选定项目

时间:2016-03-07 16:07:44

标签: typo3 typo3-6.2.x

我正在编写一个通过FlexForms配置的扩展程序。 FlexForm的一个元素是'select'类型,maxitems> 1.我使用itemsProcFunc来调用修改'items'数组的外部类方法。

到目前为止这个工作正常,但是当我尝试在BE中保存插件选项时,'Selected:'下的条目消失了。但是,正确存储选定的值。请参阅下面的flexform配置。

<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;
}

当打印flexfrom时,我得到2 xml记录,其中一个包含存储在xml中的逗号分隔值,而另一个具有空值。有人可以帮我这个吗?

1 个答案:

答案 0 :(得分:2)

我认为你应该返回config而不是params。

我的一个工作示例,可能是你的帮助:
TYPO3 v7.6.2

-FlexForm设置

<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;
}