Get TYPO3 Plugin settings from FlexForms in controller

♀尐吖头ヾ 提交于 2021-01-24 08:09:29

问题


I have a FE Plugin which uses a FlexForm MyExtFlexForm which is used to set certain configurations like limit or SourcePage etc..

In my controller action list I get these settings using $this->settings. Works fine till now.

Now, I make AJAX calls to action update and I need to use the same settings which have been set earlier through the FlexForm for the FE plugin on this page. $this->settings does not show anything.

I checked $GLOBALS['TSFE']->tmpl->setup['plugin']['MyExt.']['settings.'] and none of the settings defined in FlexForm show here.

How do I solve this issue?

EDIT:

My sample Flexform looks like this:

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

Then I make an AJAX call to my controller action and print this $this->settings , shows no settings.


回答1:


I just came across a solution: https://forum.typo3.org/index.php/t/194022/eigener-extbase-controller-keine-flexform-werte

I was including the plugin like this:

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

In order to load the settings correctly it should be:

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



回答2:


The easiest solution is proper naming fields in FlexForm ie, if your field will be prefixed with settings. it will be visible in $this->settings array:

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

Controller:

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

On the other hand if you're planning to merge TS settings with FlexForm settings you can prefix it additionaly with some other word like: <settings.flexform.myField> and then access it:

$fromTypoScript = $this->settings['myField'];
$fromFlexform   = $this->settings['flexform']['myField'];

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


来源:https://stackoverflow.com/questions/19701908/get-typo3-plugin-settings-from-flexforms-in-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!