Pet*_*ume 6 typo3 typoscript typo3-9.x
如何迁移此 TypoScript 条件以与 Symfony 表达式语言完全兼容 TYPO3 9.5 中的条件?
[userFunc = TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('fluid_styled_content')]
您目前必须提供自己的功能。
这里有一个教程:https ://usetypo3.com/symfony-expression-language-in-typo3.html
但基本上你的文件yourext/Configuration/ExpressionLanguage.php内容如下:
<?php
return [
'typoscript' => [
\Vendor\Yourext\ExpressionLanguage\ConditionProvider::class
]
];
Run Code Online (Sandbox Code Playgroud)
这会为打字稿上下文注册一个条件提供程序。
要添加简单的函数,您需要将函数提供程序类设置为expressionLanguageProviders该类的 。
可能看起来像这样:
<?php
namespace Vendor\Yourext\ExpressionLanguage;
use TYPO3\CMS\Core\ExpressionLanguage\AbstractProvider;
class ConditionProvider extends AbstractProvider
{
public function __construct()
{
$this->expressionLanguageProviders = [
UtilitiesConditionFunctionsProvider::class,
SomeOtherConditionFunctionsProvider::class,
AThirdConditionFunctionsProvider::class,
];
}
}
Run Code Online (Sandbox Code Playgroud)
(也许甚至直接在属性上设置它,而不是使用构造函数,但这就是我所做的)。
这些函数提供者需要实现\Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface接口,该接口基本上只是一个getFunctions需要返回\Symfony\Component\ExpressionLanguage\ExpressionFunction实例数组的方法。
我的 UtilitiesConditionFunctionsProvider 如下所示:
<?php
namespace Vendor\Yourext\ExpressionLanguage;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
class UtilitiesConditionFunctionsProvider implements ExpressionFunctionProviderInterface
{
/**
* @return ExpressionFunction[] An array of Function instances
*/
public function getFunctions()
{
return [
$this->getIntersectsFunction(),
$this->getExtensionLoadedFunction(),
];
}
/**
* @return ExpressionFunction
*/
protected function getIntersectsFunction()
{
return new ExpressionFunction('intersects', function () {
// Not implemented, we only use the evaluator
}, function ($arguments, $left, $right) {
return count(array_intersect($left, $right)) > 0;
});
}
protected function getExtensionLoadedFunction()
{
return new ExpressionFunction('loaded', function () {
// Not implemented, we only use the evaluator
}, function ($arguments, $extKey) {
return ExtensionManagementUtility::isLoaded($extKey);
});
}
}
Run Code Online (Sandbox Code Playgroud)
这样,现在就可以在我的条件下使用intersects( ... )和 了loaded( ... )。
| 归档时间: |
|
| 查看次数: |
844 次 |
| 最近记录: |