Friendica Storage Backend Addon development =========================================== * [Home](help) Storage backends can be added via addons. A storage backend is implemented as a class, and the plugin register the class to make it available to the system. ## The Storage Backend Class The class must live in `Friendica\Addon\youraddonname` namespace, where `youraddonname` the folder name of your addon. There are two different interfaces you need to implement. ### `ICanWriteToStorage` The class must implement `Friendica\Core\Storage\Capability\ICanWriteToStorage` interface. All method in the interface must be implemented: ```php namespace Friendica\Core\Storage\Capability\ICanWriteToStorage; interface ICanWriteToStorage { public function get(string $reference); public function put(string $data, string $reference = ''); public function delete(string $reference); public function __toString(); public static function getName(); } ``` - `get(string $reference)` returns data pointed by `$reference` - `put(string $data, string $reference)` saves data in `$data` to position `$reference`, or a new position if `$reference` is empty. - `delete(string $reference)` delete data pointed by `$reference` ### `ICanConfigureStorage` Each storage backend can have options the admin can set in admin page. To make the options possible, you need to implement the `Friendica\Core\Storage\Capability\ICanConfigureStorage` interface. All methods in the interface must be implemented: ```php namespace Friendica\Core\Storage\Capability\ICanConfigureStorage; interface ICanConfigureStorage { public function getOptions(); public function saveOptions(array $data); } ``` - `getOptions()` returns an array with details about each option to build the interface. - `saveOptions(array $data)` get `$data` from admin page, validate it and save it. The array returned by `getOptions()` is defined as: [ 'option1name' => [ ..info.. ], 'option2name' => [ ..info.. ], ... ] An empty array can be returned if backend doesn't have any options. The info array for each option is defined as: [ 'type', define the field used in form, and the type of data. one of 'checkbox', 'combobox', 'custom', 'datetime', 'input', 'intcheckbox', 'password', 'radio', 'richtext', 'select', 'select_raw', 'textarea' 'label', Translatable label of the field. This label will be shown in admin page value, Current value of the option 'help text', Translatable description for the field. Will be shown in admin page extra data Optional. Depends on which 'type' this option is: - 'select': array `[ value => label ]` of choices - 'intcheckbox': value of input element - 'select_raw': prebuild html string of `