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 keys

Using hooks it is possible to create classes that can interpret new keys. The first step is to create a class that implements the \Cobweb\Expressions\KeyProcessorInterface interface. This interface defines a single method called getValue() which is expected to return some value after having interpreted the string it receives. What the method receives is the part of the expression that comes after the colon. For example, if the expression is:

key:value1|value2|value3...

the method will received "value1|value2|value3" as argument. The method should handle that string and return whatever makes sense. It may throw exceptions to show that the input was not valid and didn't lead to a valid result.

If an exception is to be thrown, it is advised to throw a \Cobweb\Expressions\Exception\Exception or some descendant of it.

The class must then be registered in your extension's ext\_localconf.php file, using the following syntax:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['expressions']['keyProcessor'][key] = 'Vendor\\MyExtension\\Processor\\MyKeyProcessor';

Important

This differs slightly from usual hooks. In this case the expression key that can be interpreted by the class is used as a key in the hook array. The advantage is that all registered hooks are not called unnecessarily every time a custom key is found. The limitation is that there can be only one registered hook per custom key, but it wouldn't make sense anyway to have several classes to handle the same custom key.

Example

Assume the following expression must be parsed:

negative:yes

The class to handle it will have to be registered as:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['expressions']['keyProcessor']['negative'] = 'Vendor\\MyExtension\\Processor\\MyKeyProcessor';

It will receive "yes" as an input. The code of the class may be something like:

namespace Vendor\MyExtension\Processor;
class MyKeyProcessor implements \Cobweb\Expressions\KeyProcessorInterface {
        public function getValue($indices) {
                $value = 'Yes';
                if ($indices == 'yes') {
                        $value = 'No';
                }
                return $value;
        }
}

In the above example, it will return "No".