X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fdemo_plugin%2Fdemo_plugin.php;h=15cfc2c51cd4889cc0d38f821e0ab856806a4167;hb=baac4388b1696fb39f1b0bd621d215bba2da2ca8;hp=7335c9d4665a0429549d7fd3977ca961f81e58fa;hpb=7fde6de1212323418401c15efba06026c704ca87;p=github%2Fshaarli%2FShaarli.git
diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php
index 7335c9d4..15cfc2c5 100644
--- a/plugins/demo_plugin/demo_plugin.php
+++ b/plugins/demo_plugin/demo_plugin.php
@@ -1,11 +1,14 @@
get('toto', 'nope');
+ if (! $conf->exists('translation.extensions.demo')) {
+ // Custom translation with the domain 'demo'
+ $conf->set('translation.extensions.demo', 'plugins/demo_plugin/languages/');
+ $conf->write(true);
+ }
+
$errors[] = 'This a demo init error.';
return $errors;
}
+function demo_plugin_register_routes(): array
+{
+ return [
+ [
+ 'method' => 'GET',
+ 'route' => '/custom',
+ 'callable' => 'Shaarli\DemoPlugin\DemoPluginController:index',
+ ],
+ ];
+}
+
/**
* Hook render_header.
- * Executed on every page redering.
+ * Executed on every page render.
*
* Template placeholders:
* - buttons_toolbar
@@ -46,26 +88,78 @@ function demo_plugin_init($conf)
function hook_demo_plugin_render_header($data)
{
// Only execute when linklist is rendered.
- if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) {
-
+ if ($data['_PAGE_'] == TemplatePage::LINKLIST) {
// If loggedin
if ($data['_LOGGEDIN_'] === true) {
- // Buttons in toolbar
- $data['buttons_toolbar'][] = '
DEMO_buttons_toolbar';
+ /*
+ * Links in toolbar:
+ * A link is an array of its attributes (key="value"),
+ * and a mandatory `html` key, which contains its value.
+ */
+ $button = [
+ 'attr' => [
+ 'href' => '#',
+ 'class' => 'mybutton',
+ 'title' => 'hover me',
+ ],
+ 'html' => 'DEMO buttons toolbar',
+ ];
+ $data['buttons_toolbar'][] = $button;
}
- // Fields in toolbar
- $data['fields_toolbar'][] = 'DEMO_fields_toolbar';
+ /*
+ * Add additional input fields in the tools.
+ * A field is an array containing:
+ * [
+ * 'form-attribute-1' => 'form attribute 1 value',
+ * 'form-attribute-2' => 'form attribute 2 value',
+ * 'inputs' => [
+ * [
+ * 'input-1-attribute-1 => 'input 1 attribute 1 value',
+ * 'input-1-attribute-2 => 'input 1 attribute 2 value',
+ * ],
+ * [
+ * 'input-2-attribute-1 => 'input 2 attribute 1 value',
+ * ],
+ * ],
+ * ]
+ * This example renders as:
+ *
+ */
+ $form = [
+ 'attr' => [
+ 'method' => 'GET',
+ 'action' => $data['_BASE_PATH_'] . '/',
+ 'class' => 'addform',
+ ],
+ 'inputs' => [
+ [
+ 'type' => 'text',
+ 'name' => 'demo',
+ 'placeholder' => 'demo',
+ ]
+ ]
+ ];
+ $data['fields_toolbar'][] = $form;
}
// Another button always displayed
- $data['buttons_toolbar'][] = 'DEMO';
+ $button = [
+ 'attr' => [
+ 'href' => '#',
+ ],
+ 'html' => 'Demo',
+ ];
+ $data['buttons_toolbar'][] = $button;
return $data;
}
/**
* Hook render_includes.
- * Executed on every page redering.
+ * Executed on every page render.
*
* Template placeholders:
* - css_files
@@ -89,7 +183,7 @@ function hook_demo_plugin_render_includes($data)
/**
* Hook render_footer.
- * Executed on every page redering.
+ * Executed on every page render.
*
* Template placeholders:
* - text
@@ -106,8 +200,8 @@ function hook_demo_plugin_render_includes($data)
*/
function hook_demo_plugin_render_footer($data)
{
- // footer text
- $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.';
+ // Footer text
+ $data['text'][] = '
' . demo_plugin_t('Shaarli is now enhanced by the awesome demo_plugin.');
// Free elements at the end of the page.
$data['endofpage'][] = '