Collection methods are registered with the
They are used for all CMS collections (
Users as well as
For a full list of default collection methods, please check out the Reference.
You can extend the set of defined collection methods in a plugin file.
This example shows the basic architecture of a collection method. You define the method name with the key for the
collectionMethods extension array.
$this in the callback function refers to the
The example will return an array of collection item IDs.
In some cases it might be helpful to be able to pass arguments to the method.
You can define arguments for a method like this:
And then use it like this:
<?= $collection->toCustomArray('title') ?>
This example will return the titles of all collection items.