EvaluateModifierFunctionEvent
New in version 12.0
This event is a substitution of the
$GLOBALS
hook.
The PSR-14 event
\TYPO3\
allows custom TypoScript functions using the :=
operator.
Example
A simple TypoScript example looks like this:
someIdentifier = originalValue
someIdentifier := myModifierFunction(myFunctionArgument)
The corresponding event listener class could look like this:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\TypoScript\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\TypoScript\AST\Event\EvaluateModifierFunctionEvent;
#[AsEventListener(
identifier: 'my-extension/evaluate-modifier-function',
)]
final readonly class MyEventListener
{
public function __invoke(EvaluateModifierFunctionEvent $event): void
{
if ($event->getFunctionName() === 'myModifierFunction') {
$originalValue = $event->getOriginalValue();
$functionArgument = $event->getFunctionArgument();
// Manipulate values and set new value
$event->setValue($originalValue . ' example ' . $functionArgument);
}
}
}
New in version 13.0
The PHP attribute \TYPO3\
has been
introduced to tag a PHP class as an event listener. Alternatively, or if you
need to be compatible with older TYPO3 versions, you can also register an
event listener via the Configuration/
file. Switch to
an older version of this page for an example or have a look at the section
Implementing an event listener in your extension.
API
- class EvaluateModifierFunctionEvent
-
- Fully qualified name
-
\TYPO3\
CMS\ Core\ Typo Script\ AST\ Event\ Evaluate Modifier Function Event
Listeners to this event are able to implement own ":=" TypoScript modifier functions, example:
foo = myOriginalValue foo := myNewFunction(myFunctionArgument)
Listeners should take care function names can not overlap with function names from other extensions and should thus namespace, example naming: "extNewsSortFunction()"
- getFunctionName ( )
-
The function name, for example "extNewsSortFunction" when using "foo := extNewsSortFunction()"
- Returns
-
string
- getFunctionArgument ( )
-
Optional function argument, for example "myArgument" when using "foo := extNewsSortFunction(myArgument)" If the argument contained constants, those have been resolved at this point.
- Returns
-
string
- getOriginalValue ( )
-
Original / current value, for example "fooValue" when using: foo = fooValue foo := extNewsSortFunction(myArgument)
- Returns
-
?string