Field methods are registered with the
For a full list of default field methods, please check out the Reference.
Be aware that you cannot override these default field methods with any custom field method.
This example shows the basic architecture of creating a new field method. You define the method name with the array key for the
fieldsMethod array. The callback function receives the
$field object as first argument.
The object passed to the callback function gives you access to three important attributes.
||Name of the field|
||Raw content of the field|
There are three common scenarios, what field methods can do:
If you want to make it possible that the field value can be further modified by other field methods, you must modify the field value by overwriting/modifying
$field->value and returning the
When you directly return the modified value, further chaining is not possible.
Field methods can also be used to make if clauses easier or return info about a value, such as the length or the readingtime.
In some cases it might be helpful to be able to pass arguments to the method:
The definition for such a method with arguments is very simple: