diff --git a/admin.php b/admin.php index 556282d3..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; + } + } + } }; } @@ -223,6 +243,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 }}