diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-09-01 13:33:50 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-09-03 15:08:08 +0200 |
commit | 80b708a8780b91b092c3a372342959eeca742802 (patch) | |
tree | af4df63dd9dae3753d477d44d4fc569fc45c3ac8 /application | |
parent | 0e60b7f1741c35b68a37e0705521669e1191774e (diff) | |
download | Shaarli-80b708a8780b91b092c3a372342959eeca742802.tar.gz Shaarli-80b708a8780b91b092c3a372342959eeca742802.tar.zst Shaarli-80b708a8780b91b092c3a372342959eeca742802.zip |
Inject BookmarkServiceInterface in plugins data
Related discussion: ilesinge/shaarli-related#7
Diffstat (limited to 'application')
-rw-r--r-- | application/front/controller/admin/ShaarliAdminController.php | 2 | ||||
-rw-r--r-- | application/front/controller/visitor/ShaarliVisitorController.php | 26 | ||||
-rw-r--r-- | application/plugin/PluginManager.php | 4 |
3 files changed, 18 insertions, 14 deletions
diff --git a/application/front/controller/admin/ShaarliAdminController.php b/application/front/controller/admin/ShaarliAdminController.php index 3b5939bb..c26c9cbe 100644 --- a/application/front/controller/admin/ShaarliAdminController.php +++ b/application/front/controller/admin/ShaarliAdminController.php | |||
@@ -4,9 +4,7 @@ declare(strict_types=1); | |||
4 | 4 | ||
5 | namespace Shaarli\Front\Controller\Admin; | 5 | namespace Shaarli\Front\Controller\Admin; |
6 | 6 | ||
7 | use Shaarli\Container\ShaarliContainer; | ||
8 | use Shaarli\Front\Controller\Visitor\ShaarliVisitorController; | 7 | use Shaarli\Front\Controller\Visitor\ShaarliVisitorController; |
9 | use Shaarli\Front\Exception\UnauthorizedException; | ||
10 | use Shaarli\Front\Exception\WrongTokenException; | 8 | use Shaarli\Front\Exception\WrongTokenException; |
11 | use Shaarli\Security\SessionManager; | 9 | use Shaarli\Security\SessionManager; |
12 | use Slim\Http\Request; | 10 | use Slim\Http\Request; |
diff --git a/application/front/controller/visitor/ShaarliVisitorController.php b/application/front/controller/visitor/ShaarliVisitorController.php index f17c8ed3..cd27455b 100644 --- a/application/front/controller/visitor/ShaarliVisitorController.php +++ b/application/front/controller/visitor/ShaarliVisitorController.php | |||
@@ -78,16 +78,14 @@ abstract class ShaarliVisitorController | |||
78 | 'footer', | 78 | 'footer', |
79 | ]; | 79 | ]; |
80 | 80 | ||
81 | $parameters = $this->buildPluginParameters($template); | ||
82 | |||
81 | foreach ($common_hooks as $name) { | 83 | foreach ($common_hooks as $name) { |
82 | $pluginData = []; | 84 | $pluginData = []; |
83 | $this->container->pluginManager->executeHooks( | 85 | $this->container->pluginManager->executeHooks( |
84 | 'render_' . $name, | 86 | 'render_' . $name, |
85 | $pluginData, | 87 | $pluginData, |
86 | [ | 88 | $parameters |
87 | 'target' => $template, | ||
88 | 'loggedin' => $this->container->loginManager->isLoggedIn(), | ||
89 | 'basePath' => $this->container->basePath, | ||
90 | ] | ||
91 | ); | 89 | ); |
92 | $this->assignView('plugins_' . $name, $pluginData); | 90 | $this->assignView('plugins_' . $name, $pluginData); |
93 | } | 91 | } |
@@ -95,19 +93,23 @@ abstract class ShaarliVisitorController | |||
95 | 93 | ||
96 | protected function executePageHooks(string $hook, array &$data, string $template = null): void | 94 | protected function executePageHooks(string $hook, array &$data, string $template = null): void |
97 | { | 95 | { |
98 | $params = [ | ||
99 | 'target' => $template, | ||
100 | 'loggedin' => $this->container->loginManager->isLoggedIn(), | ||
101 | 'basePath' => $this->container->basePath, | ||
102 | ]; | ||
103 | |||
104 | $this->container->pluginManager->executeHooks( | 96 | $this->container->pluginManager->executeHooks( |
105 | $hook, | 97 | $hook, |
106 | $data, | 98 | $data, |
107 | $params | 99 | $this->buildPluginParameters($template) |
108 | ); | 100 | ); |
109 | } | 101 | } |
110 | 102 | ||
103 | protected function buildPluginParameters(?string $template): array | ||
104 | { | ||
105 | return [ | ||
106 | 'target' => $template, | ||
107 | 'loggedin' => $this->container->loginManager->isLoggedIn(), | ||
108 | 'basePath' => $this->container->basePath, | ||
109 | 'bookmarkService' => $this->container->bookmarkService | ||
110 | ]; | ||
111 | } | ||
112 | |||
111 | /** | 113 | /** |
112 | * Simple helper which prepend the base path to redirect path. | 114 | * Simple helper which prepend the base path to redirect path. |
113 | * | 115 | * |
diff --git a/application/plugin/PluginManager.php b/application/plugin/PluginManager.php index 2d93cb3a..7881e3be 100644 --- a/application/plugin/PluginManager.php +++ b/application/plugin/PluginManager.php | |||
@@ -112,6 +112,10 @@ class PluginManager | |||
112 | $data['_BASE_PATH_'] = $params['basePath']; | 112 | $data['_BASE_PATH_'] = $params['basePath']; |
113 | } | 113 | } |
114 | 114 | ||
115 | if (isset($params['bookmarkService'])) { | ||
116 | $data['_BOOKMARK_SERVICE_'] = $params['bookmarkService']; | ||
117 | } | ||
118 | |||
115 | foreach ($this->loadedPlugins as $plugin) { | 119 | foreach ($this->loadedPlugins as $plugin) { |
116 | $hookFunction = $this->buildHookName($hook, $plugin); | 120 | $hookFunction = $this->buildHookName($hook, $plugin); |
117 | 121 | ||