useStdWrap 与 tx_news 中的 overrideFlexformSettingsIfEmpty 冲突
useStdWrap conflicts with overrideFlexformSettingsIfEmpty in tx_news
在 tx_news 中,所有插件设置也可以通过 TypoScript 设置,方法是将它们的名称添加到 overrideFlexformSettingsIfEmpty
。顾名思义,这些基于 TS 的设置仅在任何插件化身的相应 Flexform 字段留空时才会使用。这就是我想要的,也是我需要的。它允许可以在每个插件元素中覆盖的基本 TS 配置。
问题来了:
由于我的 TS 默认值需要更复杂的计算,我还为某些 tx_news 设置字段激活了 useStdWrap
。但是我发现一个活动的 stdWrap
总是会被使用——不管是否有 Flexform 设置。
我需要的是使用 TS stdWrap 来计算默认值的可能性,但是如果定义了 Flexform 设置,它应该始终覆盖 TS 设置(无论它们的计算有多复杂以及它是否包含 stdWrap 操作)。
这是一个例子:
plugin.tx_news.settings {
overrideFlexformSettingsIfEmpty := addToList(categories)
useStdWrap := addToList(categories)
categories.data = GP:cat
categories.ifEmpty = 1
}
我希望此 TS 从查询字符串参数 (cat) 设置任何新闻插件的类别并回落到类别 1,但是 仅 如果没有类别在插件本身中设置。
但是 stdWrap
操作(.data 和 .ifEmpty)总是 启动并且无法再使用 Flexform 设置。
有办法解决吗?
没有办法为每个人解决这个问题,因为如果改变它,就会有其他缺点。
一个解决方案是使用挂钩 $GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['Controller/NewsController.php']['overrideSettings']
,您可以在其中操纵 PHP 中的设置,拥有您需要的一切。
我接受了 Georgs 的回答,但选择了另一种方法来解决这个问题:
我创建了一个 PHP class 读取和 returns 任何给定 tx_news 插件化身的类别设置,并允许将它们合并回 useStdWrap 进程.
要使用此方法,最好创建一个基本的自定义扩展并将 PHP class 文件放入其 类 文件夹中。这是这样一个 class 文件的代码,存储为 /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;
}
}
有了这个 class,您可以在 TS 设置中读取在 tx_news 插件化身中选择的类别,使用 stdWrap 处理它们并将它们作为更新的类别值推回插件.
这是相应的 TS 设置代码的示例。
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
}
}
我们在这里做了很多花哨的事情。这只是一个例子。重要的是,插件中的类别设置优先,块 categories.ifEmpty{...}
中的所有 TS 设置仅在插件中没有正确设置类别时使用。
撰写本文时的版本:TYPO3 7.6.11、tx_news 5.2.0
在 tx_news 中,所有插件设置也可以通过 TypoScript 设置,方法是将它们的名称添加到 overrideFlexformSettingsIfEmpty
。顾名思义,这些基于 TS 的设置仅在任何插件化身的相应 Flexform 字段留空时才会使用。这就是我想要的,也是我需要的。它允许可以在每个插件元素中覆盖的基本 TS 配置。
问题来了:
由于我的 TS 默认值需要更复杂的计算,我还为某些 tx_news 设置字段激活了 useStdWrap
。但是我发现一个活动的 stdWrap
总是会被使用——不管是否有 Flexform 设置。
我需要的是使用 TS stdWrap 来计算默认值的可能性,但是如果定义了 Flexform 设置,它应该始终覆盖 TS 设置(无论它们的计算有多复杂以及它是否包含 stdWrap 操作)。
这是一个例子:
plugin.tx_news.settings {
overrideFlexformSettingsIfEmpty := addToList(categories)
useStdWrap := addToList(categories)
categories.data = GP:cat
categories.ifEmpty = 1
}
我希望此 TS 从查询字符串参数 (cat) 设置任何新闻插件的类别并回落到类别 1,但是 仅 如果没有类别在插件本身中设置。
但是 stdWrap
操作(.data 和 .ifEmpty)总是 启动并且无法再使用 Flexform 设置。
有办法解决吗?
没有办法为每个人解决这个问题,因为如果改变它,就会有其他缺点。
一个解决方案是使用挂钩 $GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['Controller/NewsController.php']['overrideSettings']
,您可以在其中操纵 PHP 中的设置,拥有您需要的一切。
我接受了 Georgs 的回答,但选择了另一种方法来解决这个问题:
我创建了一个 PHP class 读取和 returns 任何给定 tx_news 插件化身的类别设置,并允许将它们合并回 useStdWrap 进程.
要使用此方法,最好创建一个基本的自定义扩展并将 PHP class 文件放入其 类 文件夹中。这是这样一个 class 文件的代码,存储为 /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;
}
}
有了这个 class,您可以在 TS 设置中读取在 tx_news 插件化身中选择的类别,使用 stdWrap 处理它们并将它们作为更新的类别值推回插件.
这是相应的 TS 设置代码的示例。
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
}
}
我们在这里做了很多花哨的事情。这只是一个例子。重要的是,插件中的类别设置优先,块 categories.ifEmpty{...}
中的所有 TS 设置仅在插件中没有正确设置类别时使用。
撰写本文时的版本:TYPO3 7.6.11、tx_news 5.2.0