From 80b708a8780b91b092c3a372342959eeca742802 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 1 Sep 2020 13:33:50 +0200 Subject: Inject BookmarkServiceInterface in plugins data Related discussion: ilesinge/shaarli-related#7 --- .../visitor/ShaarliVisitorController.php | 26 ++++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'application/front/controller/visitor/ShaarliVisitorController.php') 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 'footer', ]; + $parameters = $this->buildPluginParameters($template); + foreach ($common_hooks as $name) { $pluginData = []; $this->container->pluginManager->executeHooks( 'render_' . $name, $pluginData, - [ - 'target' => $template, - 'loggedin' => $this->container->loginManager->isLoggedIn(), - 'basePath' => $this->container->basePath, - ] + $parameters ); $this->assignView('plugins_' . $name, $pluginData); } @@ -95,19 +93,23 @@ abstract class ShaarliVisitorController protected function executePageHooks(string $hook, array &$data, string $template = null): void { - $params = [ - 'target' => $template, - 'loggedin' => $this->container->loginManager->isLoggedIn(), - 'basePath' => $this->container->basePath, - ]; - $this->container->pluginManager->executeHooks( $hook, $data, - $params + $this->buildPluginParameters($template) ); } + protected function buildPluginParameters(?string $template): array + { + return [ + 'target' => $template, + 'loggedin' => $this->container->loginManager->isLoggedIn(), + 'basePath' => $this->container->basePath, + 'bookmarkService' => $this->container->bookmarkService + ]; + } + /** * Simple helper which prepend the base path to redirect path. * -- cgit v1.2.3