从控制器中的 FlexForms 获取 TYPO3 插件设置


Get TYPO3 Plugin settings from FlexForms in controller

我有一个FE插件,它使用FlexForm MyExtFlexForm用于设置某些配置,例如limit or SourcePage etc..

在我的控制器操作list中,我使用 $this->settings 获得这些设置。到目前为止工作正常。

现在,我发出 AJAX 号召性用语update并且我需要使用之前通过此页面上的 FE 插件的 FlexForm 设置的相同设置。 $this->settings does not show anything .

我检查了$GLOBALS['TSFE']->tmpl->setup['plugin']['MyExt.']['settings.'],此处未显示 FlexForm 中定义的任何设置。

如何解决此问题?

编辑:

我的示例弹性表单如下所示:

<sheets>
        <sDEF>
            <ROOT>
                <TCEforms>
                    <sheetTitle>View Settings</sheetTitle>
                </TCEforms>
                <type>array</type>
                <el>
                    <switchableControllerActions>
                        <TCEforms>
                            <label>Select</label>
                            <config>
                                <type>select</type>
                                <items>
                                    <numIndex index="0">
                                        <numIndex index="0">MyFunction</numIndex>
                                        <numIndex index="1">MyExt->list</numIndex>
                                    </numIndex>
                                </items>
                            </config>
                        </TCEforms>
                    </switchableControllerActions>
                    <settings.flexform.limit>
                        <TCEforms>
                            <label>Number of items to be displayed</label>
                            <config>
                                <type>input</type>
                                <size>10</size>
                            </config>
                        </TCEforms>
                    </settings.flexform.limit>
                </el>
            </ROOT>
        </sDEF>
    </sheets>

然后我对我的控制器操作进行 AJAX 调用并打印此$this->settings,不显示任何设置。

我刚刚遇到了一个解决方案:https://forum.typo3.org/index.php/t/194022/eigener-extbase-controller-keine-flexform-werte

我像这样包含插件:

AJAX_PAGE = PAGE
AJAX_PAGE {
    typeNum = 2
    10 < tt_content.list.20.myPlugin
    config {
        disableAllHeaderCode = 1
        xhtml_cleaning = 0
        admPanel = 0
        debug = 0
        no_cache = 1
    }
}

为了正确加载设置,它应该是:

AJAX_PAGE = PAGE
AJAX_PAGE {
    typeNum = 2
    10 < styles.content.get
    10 {
        select.where = colpos = 0
        select.andWhere = list_type='myPlugin'
    }
    config {
        disableAllHeaderCode = 1
        xhtml_cleaning = 0
        admPanel = 0
        debug = 0
        no_cache = 1
    }
}

最简单的解决方案是在 FlexForm 中正确命名字段,即,如果您的字段将以 settings. 为前缀,它将在数组$this->settings可见:

<settings.myField>
    <TCEforms>
        <label>My very special setting</label>
        <config>
            <type>input</type>
        </config>
    </TCEforms>
</settings.myField>

控制器:

$mySetting = $this->settings['myField'];

另一方面,如果您打算将 TS 设置与 FlexForm 设置合并,则可以在它前面加上一些其他单词,例如:<settings.flexform.myField>,然后访问它:

$fromTypoScript = $this->settings['myField'];
$fromFlexform   = $this->settings['flexform']['myField'];
// or...
$myMergedSetting = (!$this->settings['flexform']['myField'])
                   ? $this->settings['myField']
                   : $this->settings['flexform']['myField'];