From ce31ccaade3874233950e283b580007ea314f3aa Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Wed, 12 Dec 2018 20:36:56 +0100 Subject: [PATCH] Add docs about storage backend --- doc/AddonStorageBackend.md | 202 +++++++++++++++++++++++++++++++++++++ doc/Home.md | 1 + doc/Settings.md | 25 +++++ doc/tools.md | 3 + 4 files changed, 231 insertions(+) create mode 100644 doc/AddonStorageBackend.md diff --git a/doc/AddonStorageBackend.md b/doc/AddonStorageBackend.md new file mode 100644 index 0000000000..d6ad9d37db --- /dev/null +++ b/doc/AddonStorageBackend.md @@ -0,0 +1,202 @@ +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 avaiable to the system. + +## The Storage Backend Class + +The class must live in `Friendica\Addon\youraddonname` namespace, where `youraddonname` the folder name of your addon. + +The class must implement `Friendica\Model\Storage\IStorage` interface. All method in the interface must be implemented: + +namespace Friendica\Model\Storage; + + interface IStorage + { + public static function get($ref); + public static function put($data, $ref = ""); + public static function delete($ref); + public static function getOptions(); + public static function saveOptions($data); + } + +- `get($ref)` returns data pointed by `$ref` +- `put($data, $ref)` saves data in `$data` to position `$ref`, or a new position if `$ref` is empty. +- `delete($ref)` delete data pointed by `$ref` + +Each storage backend can have options the admin can set in admin page. + +- `getOptions()` returns an array with details about each option to build the interface. +- `saveOptions($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', 'yesno' + + '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 `