useStdWrap conflicts with overrideFlexformSettingsIfEmpty in tx_news

拥有回忆 提交于 2019-12-12 02:25:16

问题


In tx_news all plugin settings can also be set via TypoScript by adding their names to overrideFlexformSettingsIfEmpty. As the name suggests, these TS based settings are only used, if the corresponding Flexform fields of any plugin incarnation are left empty. This is what I want and what I need. It allows for a basic TS configuration that can be overwritten within each plugin element.

Now here's the problem:

As my TS default values need more complex calculations, I also activate useStdWrap for some of the tx_news settings fields. But I found that an active stdWrap will ALWAYS be used – no matter whether there are Flexform settings or not.

What I need is the possibility to use TS stdWrap to calculate default values, but if a Flexform setting is defined it should always override the TS settings (no matter how complex their calculation was and whether it included stdWrap operations).

Here is an example:

plugin.tx_news.settings {
    overrideFlexformSettingsIfEmpty := addToList(categories)
    useStdWrap := addToList(categories)

    categories.data = GP:cat
    categories.ifEmpty = 1
}

I would expect this TS to set the category of any news plugin from a query string parameter (cat) and fall back to category 1, but only if there are no categories set within the plugin itself.

But the stdWrap operations (.data and .ifEmpty) always kick in and there is no way to use the Flexform settings any more.

Is there a way to solve this?


回答1:


There is no way to fix this for everybody because if it would be changed, there would be other drawbacks.

One solution would be to use the hook $GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['Controller/NewsController.php']['overrideSettings'] where you can manipulate the settings in PHP having everything you need.




回答2:


I have accepted Georgs answer but chosen another way to solve this problem:

I have created a PHP class that reads and returns the categories setting of any given tx_news plugin incarnation and allows to merge them back into the useStdWrap process.

To use this approach it is best to create a rudimentary custom extension an put the PHP class file into its Classes folder. Here is the code of such a class file, stored as /your_extension/Classes/TsSetupHelper.php:

<?php
namespace YourVendor\YourExtension;

class TsSetupHelper {

    /**
     * Reference to the parent (calling) cObject set from TypoScript
     */
    public $cObj;


    /**
     * Return the categories chosen in a tx_news plugin content element. 
     * Can be used in TS Setup to stdWrap the categories without losing the settings defined within a plugin incarnation.
     *
     * @param  string          Empty string (no content to process)
     * @param  array           TypoScript configuration
     * @return string          return categorie value list from plugin in page, e.g.: '1,3,4'
     */
    public function getNewsPluginCategory($content, $conf) {

        $newsPluginFlexformArr = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array( $this->cObj->data['pi_flexform'] );
        $newsPluginCategories = $newsPluginFlexformArr['data']['sDEF']['lDEF']['settings.categories']['vDEF'];

        return $newsPluginCategories;
    }
}

With this class in place, you can read in the categories chosen in a tx_news plugin incarnation in TS Setup, process them using stdWrap and push them back into to plugin as updated categories values.

Here is an example of a corresponding TS Setup code.

plugin.tx_news.settings {
    overrideFlexformSettingsIfEmpty := addToList(categories,categoryConjunction)
    useStdWrap := addToList(categories)
    categoryConjunction = or

    # pre fill categories with value from plugin in page
    categories.cObject = USER
    categories.cObject {
        userFunc = YourVendor\YourExtension\TsSetupHelper->getNewsPluginCategory
    }
    # only if no categories are chosen within plugin,
    # use TS to define categories:
    categories.ifEmpty {
        # get cat from parameter in query
        data = GP:cat
        # ignore cat parameter if page layout 5 is chosen in page properties
        override = 1,2,3,4,5,6,7,8,9,10
        override.if.value.data = page:layout
        override.if.equals = 5
        # default categories to 3 if cat param is not set
        ifEmpty = 3
    }
}

We do a lot of fancy stuff here. It is all meant as an example. The important part is, that the categories setting within the plugin takes precedence and all the TS settings in the block categories.ifEmpty{...} are only used, if there are no categories set right within the plugin.

Versions at time of this writing: TYPO3 7.6.11, tx_news 5.2.0



来源:https://stackoverflow.com/questions/39962216/usestdwrap-conflicts-with-overrideflexformsettingsifempty-in-tx-news

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