EvaluateModifierFunctionEvent

New in version 12.0

The PSR-14 event \TYPO3\CMS\Core\TypoScript\AST\Event\EvaluateModifierFunctionEvent allows custom TypoScript functions using the := operator.

Example

A simple TypoScript example looks like this:

EXT:my_extension/Configuration/TypoScript/setup.typoscript
someIdentifier = originalValue
someIdentifier := myModifierFunction(myFunctionArgument)
Copied!

The corresponding event listener class could look like this:

EXT:my_extension/Classes/TypoScript/EventListener/MyEventListener.php
<?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);
        }
    }
}
Copied!

New in version 13.0

API

class EvaluateModifierFunctionEvent
Fully qualified name
\TYPO3\CMS\Core\TypoScript\AST\Event\EvaluateModifierFunctionEvent

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
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