EvaluateModifierFunctionEvent

New in version 12.0

This event is a substitution of the $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsparser.php']['preParseFunc'] hook.

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

The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener 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/Services.yaml 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 \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()"

returntype

string

getFunctionArgument ( )

Optional function argument, for example "myArgument" when using "foo := extNewsSortFunction(myArgument)"

returntype

string

getOriginalValue ( )

Original / current value, for example "fooValue" when using: foo = fooValue foo := extNewsSortFunction(myArgument)

returntype

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 string $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().

returntype

string