如何访问 typoscript 中的 ext_conf_template.txt(扩展配置)?

How to access the ext_conf_template.txt (extension configuration) in typoscript?

我的扩展程序 ext_conf_template.txt 中有一些设置。

我想检查其中一个设置的值,但在 typoscript 中,而不是在 PHP 中。

在PHP中它是这样工作的:

unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['myExt'])

我应该如何在打字错误中做到这一点?

我在我的代码片段扩展中做了类似的事情(参见完整的 code on Github),我只是在其中添加了自定义 TypoScript 条件:

[DanielGoerz\FsCodeSnippet\Configuration\TypoScript\ConditionMatching\AllLanguagesCondition]
  // some conditional TS
[global]

条件实现很简单:

namespace DanielGoerz\FsCodeSnippet\Configuration\TypoScript\ConditionMatching;
use DanielGoerz\FsCodeSnippet\Utility\FsCodeSnippetConfigurationUtility;
use TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractCondition;

class AllLanguagesCondition extends AbstractCondition
{
    /**
     * Check whether allLanguages is enabled
     * @param array $conditionParameters
     * @return bool
     */
    public function matchCondition(array $conditionParameters)
    {
        return FsCodeSnippetConfigurationUtility::isAllLanguagesEnabled();
    }
}

并在 FsCodeSnippetConfigurationUtility:

中完成对实际 TYPO3_CONF_VARS 值的检查
namespace DanielGoerz\FsCodeSnippet\Utility;    
class FsCodeSnippetConfigurationUtility
{
    /**
     * @return array
     */
    private static function getExtensionConfiguration()
    {
        return unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fs_code_snippet']);
    }
    /**
     * @return bool
     */
    public static function isAllLanguagesEnabled()
    {
        $conf = self::getExtensionConfiguration();
        return !empty($conf['enableAllLanguages']);
    }

}

也许这符合您的需要。

通过 Extension Manager 处理配置并在 ext_localconf.php 中调用 ExtensionManagementUtility::addTypoScriptConstants() 以在运行时设置 TypoScript 常量。

这样可以在一个位置设置值,并且在低级别 PHP 和 TypoScript 设置中都可用。

感谢 Marcus 的回答,我能够将扩展配置设置输入错字中。首先在 ext_conf_template.txt:

中创建扩展设置
# cat=Storage; type=string; label=storageFolderPid
storageFolderPid = 1

ext_local_conf.php中添加以下行:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptConstants(
    "plugin.tx_extensionname.settings.storageFolderPid = ".$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['extension']['storageFolderPid']
);

然后您可以在打字错误中使用此变量,例如创建存储文件夹的子菜单:

lib.submenu = CONTENT
lib.submenu {
    table = tx_extension_domain_model_article
    select {
        pidInList = {$plugin.tx_extensionname.settings.storageFolderPid}
        selectFields = tx_extensionname_domain_model_article.*
    }
    ...
}