DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

Introducing new functionsΒΆ

Just like with keys, it is possible to use a hook to introduce custom functions, which makes it possible to do pretty much whatever one wants with expressions. An example class is provided in Classes/Sample/FunctionProcessor.php . It introduces a function called "offset". To make this function available, it must be registered as follows:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['expressions']['customFunction']['offset'] = 'Cobweb\\Expressions\\Sample\\FunctionProcessor->offset';

The function itself looks like this:

public function offset($parameters, $parentObject) {
        $value = intval($parameters[0]);
        $offset = 0;
        if (isset($parameters[1])) {
                $offset = intval($parameters[1]);
        }
        return $value + $offset;
}

It receives an array containing the function call parameters and what would normally be a back-reference to the calling object, but is actually a dummy object, since the \Cobweb\Expressions\ExpressionParser class is purely static. The call parameters array is an indexed array containing:

  • at index 0, the value that was calculated from the expression
  • at index 1 and more, any additional parameters that were defined in the function call.

As an example, consider the following expression using this custom function:

gp:foo->offset:5

The offset() method will receive the value of "gp:foo" in $parameters[0] and "5" in $parameters[1].

The function is expected to return the modified value, or the original value from the expression if no change happened.