How to access the ext_conf_template.txt (extension

2019-07-25 21:45发布

问题:

There are a few settings in the ext_conf_template.txt in my extension.

I want to check the value of one of these settings, but in typoscript, not in PHP.

In PHP it works like this:

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

How should I do this in typoscript?

回答1:

I did something similar in my code snippet extension (see complete code on Github), where I just added a custom TypoScript condition:

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

The condition implementation is quite simple:

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();
    }
}

And the check for the actual TYPO3_CONF_VARS value is done in FsCodeSnippetConfigurationUtility:

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']);
    }

}

Maybe that fits your needs.



回答2:

Handle the configuration via Extension Manager and call ExtensionManagementUtility::addTypoScriptConstants() in your ext_localconf.php to set a TypoScript constant at runtime.

This way the value can be set at one location and is available both in lowlevel PHP and TypoScript setup.