aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/demo_plugin
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-27 19:23:45 +0100
committerArthurHoaro <arthur@hoa.ro>2020-11-15 12:41:43 +0100
commita6e9c08499f9f79dad88cb3ae9eacda0e0c34c96 (patch)
tree41f70d7dc478e70a4a3ce4a578839316f5578765 /plugins/demo_plugin
parent6f9e0609f4c118142504234ebcc7d93456b5e588 (diff)
downloadShaarli-a6e9c08499f9f79dad88cb3ae9eacda0e0c34c96.tar.gz
Shaarli-a6e9c08499f9f79dad88cb3ae9eacda0e0c34c96.tar.zst
Shaarli-a6e9c08499f9f79dad88cb3ae9eacda0e0c34c96.zip
Plugin system: allow plugins to provide custom routes
- each route will be prefixed by `/plugin/<plugin_name>` - add a new template for plugins rendering - add a live example in the demo_plugin Check out the "Plugin System" documentation for more detail. Related to #143
Diffstat (limited to 'plugins/demo_plugin')
-rw-r--r--plugins/demo_plugin/DemoPluginController.php24
-rw-r--r--plugins/demo_plugin/demo_plugin.php19
2 files changed, 42 insertions, 1 deletions
diff --git a/plugins/demo_plugin/DemoPluginController.php b/plugins/demo_plugin/DemoPluginController.php
new file mode 100644
index 00000000..b8ace9c8
--- /dev/null
+++ b/plugins/demo_plugin/DemoPluginController.php
@@ -0,0 +1,24 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\DemoPlugin;
6
7use Shaarli\Front\Controller\Admin\ShaarliAdminController;
8use Slim\Http\Request;
9use Slim\Http\Response;
10
11class DemoPluginController extends ShaarliAdminController
12{
13 public function index(Request $request, Response $response): Response
14 {
15 $this->assignView(
16 'content',
17 '<div class="center">' .
18 'This is a demo page. I have access to Shaarli container, so I\'m free to do whatever I want here.' .
19 '</div>'
20 );
21
22 return $response->write($this->render('pluginscontent'));
23 }
24}
diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php
index 22d27b68..15cfc2c5 100644
--- a/plugins/demo_plugin/demo_plugin.php
+++ b/plugins/demo_plugin/demo_plugin.php
@@ -7,6 +7,8 @@
7 * Can be used by plugin developers to make their own plugin. 7 * Can be used by plugin developers to make their own plugin.
8 */ 8 */
9 9
10require_once __DIR__ . '/DemoPluginController.php';
11
10/* 12/*
11 * RENDER HEADER, INCLUDES, FOOTER 13 * RENDER HEADER, INCLUDES, FOOTER
12 * 14 *
@@ -60,6 +62,17 @@ function demo_plugin_init($conf)
60 return $errors; 62 return $errors;
61} 63}
62 64
65function demo_plugin_register_routes(): array
66{
67 return [
68 [
69 'method' => 'GET',
70 'route' => '/custom',
71 'callable' => 'Shaarli\DemoPlugin\DemoPluginController:index',
72 ],
73 ];
74}
75
63/** 76/**
64 * Hook render_header. 77 * Hook render_header.
65 * Executed on every page render. 78 * Executed on every page render.
@@ -304,7 +317,11 @@ function hook_demo_plugin_render_editlink($data)
304function hook_demo_plugin_render_tools($data) 317function hook_demo_plugin_render_tools($data)
305{ 318{
306 // field_plugin 319 // field_plugin
307 $data['tools_plugin'][] = 'tools_plugin'; 320 $data['tools_plugin'][] = '<div class="tools-item">
321 <a href="' . $data['_BASE_PATH_'] . '/plugin/demo_plugin/custom">
322 <span class="pure-button pure-u-lg-2-3 pure-u-3-4">Demo Plugin Custom Route</span>
323 </a>
324 </div>';
308 325
309 return $data; 326 return $data;
310} 327}