collection

Triggered on attempts to create a custom files collection. How to show a custom collection’s file list by means of a plugin:

  1. Connect the plugin to hook backend_assets and return JavaScript code adding a new method to controller $.files.controller. In that method, use a request to plugin’s PHP controller.
  2. The PHP controller must extend class filesFilesAction. Override the controller’s execute() method to create a files collection class instance with a custom hash. It is advisable to use the plugin’s ID in the hash to avoid collisions with the hashes used within the app and by other plugins.
  3. In the collection event handler, check the hash value and, if the check is successfull, modify the default behavior of the files collection class instance; e.g., by calling its methods addWhere() or addJoin().

Files

Input (passed by reference)

$params['collection'] shopProductsCollection Files collection class instance.
$params['auto_title'] bool Whether a default title must be applied to the collection.
$params['add'] bool Whether new collection initialization conditions must be applied on repeated (recursive) calls of collection class methods.
$params['hash'] string Collection hash.
$params['options'] array Additional collection options.
$params['options']['workup'] bool|callable Whether extra processing of the collection’s files must be performed.
… your plugin code …

Output

%plugin_id%
true if the specified hash is supported by the plugin.
Files

Plugin code example

PHP

public function collection($params)
{
    if ($params['hash'][0] == 'myplugin') {
        $params['collection']->addWhere('...');
        return true;
    }
}