Custom file methods

2.3.0 +

Default file methods

For a full list of default file methods, please check out the cheat sheet. Be aware that you cannot override these default file methods with any custom file method.

Getting started

You can extend the set of defined file methods very easily. The best place to do this is in a plugin file: /site/plugins/file-methods.php

file::$methods['soShiny'] = function($file) {
  return 'Everything so shiny: <a href="' . $file->url() . '">' . $file->filename() . '</a>';
};

This example shows the basic architecture of a file method. You define the method name with the key for the file::$methods array. The callback function receives the $file object as first argument.

Working with method arguments

In some cases it might be helpful to be able to pass arguments to the method:

<?= $file->soSomething('shiny') ?>

The definition for such a method with arguments is very simple:

file::$methods['soSomething'] = function($file, $adjective) {
    return 'Everything so ' . $adjective . ': <a href="' . $file->url() . '">' . $file->filename() . '</a>';
};