Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here: TYPO3 ELTS.
Symfony expression language
Symfony expression language is used by TYPO3 in certain places. These are documented in the following sections, together with explanations how they can be extended:
This page
Symfony within TypoScript conditions
In order to provide custom conditions, its essential to understand how conditions are written. Refer to The syntax of conditions for details.
Conditions are evaluated by the Symfony Expression Language and are evaluated
to boolean results. Therefore an integrator can write [true === true]
which would evaluate to true. In order to provide further functionality within
conditions, the Symfony Expression Language needs to be extended. There are two
parts that can be added to the language, which are variables and functions.
The following sections explain how to add variables and functions.
Registering new provider within an extension
There has to be a provider, no matter whether variables or functions will be provided.
The provider is registered in the extension file
Configuration/
:
return [
'typoscript' => [
\MyVendor\SomeExtension\ExpressionLanguage\CustomTypoScriptConditionProvider::class,
]
];
This will register the defined Custom
PHP class as provider within the context typoscript
.
Implement provider within extension
The provider itself is written as PHP Class within the extension file
/Classes/
, depending on
the formerly registered PHP class name:
namespace MyVendor\SomeExtension\ExpressionLanguage;
use TYPO3\CMS\Core\ExpressionLanguage\AbstractProvider;
class CustomTypoScriptConditionProvider extends AbstractProvider
{
public function __construct()
{
}
}
Additional variables
Additional variables can already be provided within the
Custom
PHP class:
class CustomTypoScriptConditionProvider extends AbstractProvider
{
public function __construct()
{
$this->expressionLanguageVariables = [
'variableA' => 'valueB',
];
}
}
In above example a new variable variable
with value value
is added, this
can be used within conditions:
[variableA === 'valueB']
page >
page = PAGE
page.10 = TEXT
page.10.value = Matched
[GLOBAL]
Additional functions
Additional functions can be provided through another class, which has to be
returned by the example Custom
PHP class:
class CustomTypoScriptConditionProvider extends AbstractProvider
{
public function __construct()
{
$this->expressionLanguageProviders = [
CustomConditionFunctionsProvider::class,
];
}
}
The returned class will look like the following:
namespace Vendor\SomeExtension\TypoScript;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class CustomConditionFunctionsProvider implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
$this->getWebserviceFunction(),
];
}
protected function getWebserviceFunction(): ExpressionFunction
{
// TODO: Implement
}
}
The class is already trying to return a new Expression
, but
currently lacks implementation. That is the last step:
protected function getWebserviceFunction(): ExpressionFunction
{
return new ExpressionFunction('webservice', function () {
// Not implemented, we only use the evaluator
}, function ($existingVariables, $endpoint, $uid) {
return GeneralUtility::getUrl(
'https://example.org/endpoint/'
. $endpoint
. '/'
. $uid
);
});
}
The first argument $existing
is an array of which each associative key corresponds to a registered variable.
- request -
\TYPO3\
CMS\ Core\ Expression Language\ Request Wrapper - applicationContext - string
- typo3 - stdClass
- tree - stdClass
- frontend - stdClass
- backend - stdClass
- workspace - stdClass
- page - array: page record
If you need an undefined number of variables, then you can write the same function in a variadic form:
// ...
}, function (...$args) {
$existingVariables = $args['0'];
// ...
}
All further arguments are provided by TypoScript. The above example could look like:
[webservice('pages', 10)]
page.10 >
page.10 = TEXT
page.10.value = Matched
[GLOBAL]
If a simple string like a page title is returned, this can be further compared:
[webservice('pages', 10) === 'Expected page title']
page.10 >
page.10 = TEXT
page.10.value = Matched
[GLOBAL]
Further information about Expression
can be found within Symfony Expression Language - Registering Functions