From 5658bad34765a72301fff7a9ce7925a784487c7c Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 7 Sep 2015 11:48:42 +0200 Subject: [PATCH 1/2] Call onAdminTemplateNavPluginHook to provide plugins the ability to populate plugins_hooked_nav Example event handling: public function onAdminTemplateNavPluginHook() { $this->grav['twig']->plugins_hooked_nav['PLUGIN_DATA.DATA'] = ['route' => 'data', 'icon' => 'fa-file-text']; } --- admin.php | 3 +++ themes/grav/templates/partials/nav.html.twig | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/admin.php b/admin.php index 556282d3..28373859 100644 --- a/admin.php +++ b/admin.php @@ -223,6 +223,9 @@ class AdminPlugin extends Plugin $twig->twig_vars['base_path'] = GRAV_ROOT; $twig->twig_vars['admin'] = $this->admin; + // Gather Plugin-hooked nav items + $this->grav->fireEvent('onAdminTemplateNavPluginHook'); + switch ($this->template) { case 'dashboard': $twig->twig_vars['popularity'] = $this->popularity; diff --git a/themes/grav/templates/partials/nav.html.twig b/themes/grav/templates/partials/nav.html.twig index 50dc4aff..ef71a508 100644 --- a/themes/grav/templates/partials/nav.html.twig +++ b/themes/grav/templates/partials/nav.html.twig @@ -31,6 +31,15 @@ + {% if grav.twig.plugins_hooked_nav %} + {% for label, item in grav.twig.plugins_hooked_nav %} +
  • + + {{ label|tu }} + +
  • + {% endfor %} + {% endif %}
  • {{ "PLUGIN_ADMIN.PLUGINS"|tu }} From a52f2c842b94778f2c0aebe5179e9537ff2e0660 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 7 Sep 2015 11:49:41 +0200 Subject: [PATCH 2/2] Allow plugins to provide pages in (plugin)/admin/pages/ --- admin.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/admin.php b/admin.php index 28373859..819a3edc 100644 --- a/admin.php +++ b/admin.php @@ -182,9 +182,29 @@ class AdminPlugin extends Plugin // Replace page service with admin. $this->grav['page'] = function () use ($self) { $page = new Page; - $page->init(new \SplFileInfo(__DIR__ . "/pages/admin/{$self->template}.md")); - $page->slug(basename($self->template)); - return $page; + + if (file_exists(__DIR__ . "/pages/admin/{$self->template}.md")) { + $page->init(new \SplFileInfo(__DIR__ . "/pages/admin/{$self->template}.md")); + $page->slug(basename($self->template)); + return $page; + } + + // If the page cannot be found, try looking in plugins. + // Allows pages added by plugins in admin + $plugins = Grav::instance()['config']->get('plugins', []); + + foreach($plugins as $plugin => $data) { + $folder = GRAV_ROOT . "/user/plugins/" . $plugin . "/admin"; + + if (file_exists($folder)) { + $file = $folder . "/pages/{$self->template}.md"; + if (file_exists($file)) { + $page->init(new \SplFileInfo($file)); + $page->slug(basename($self->template)); + return $page; + } + } + } }; }