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)
To implement my
, an extension needs to register
an event listener in an extension's Services.
:
services:
# Place here the default dependency injection configuration
MyVendor\MyExtension\TypoScript\EventListener\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/evaluate-modifier-function'
Read how to configure dependency injection in extensions.
The corresponding event listener class could look like this:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\TypoScript\EventListener;
use TYPO3\CMS\Core\TypoScript\AST\Event\EvaluateModifierFunctionEvent;
final 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);
}
}
}
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)"
- Returns
-
?string
- getOriginalValue ( ) ¶
-
Original / current value, for example "fooValue" when using: foo = fooValue foo := extNewsSortFunction(myArgument)
- Returns
-
?string
- setValue ( string $value) ¶
-
Set the updated value calculated by a listener.
Note you can not set to null to "unset", since getValue() falls back to originalValue in this case. Set to empty string instead for this edge case.
- param $value
-
the value
- getValue ( ) ¶
-
Used by AstBuilder to fetch the updated value, falls back to given original value.
Can be used by Listeners to see if a previous listener changed the value already by comparing with getOriginalValue().
- Returns
-
?string