mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-14 01:06:03 +01:00
Merge pull request #148 from getgrav/feature/allow-plugins-hook-in-admin
Feature/allow plugins hook in admin
This commit is contained in:
23
admin.php
23
admin.php
@@ -182,9 +182,29 @@ class AdminPlugin extends Plugin
|
||||
// Replace page service with admin.
|
||||
$this->grav['page'] = function () use ($self) {
|
||||
$page = new 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;
|
||||
|
||||
@@ -31,6 +31,15 @@
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
{% if grav.twig.plugins_hooked_nav %}
|
||||
{% for label, item in grav.twig.plugins_hooked_nav %}
|
||||
<li class="{{ (location == item.route) ? 'selected' : '' }}">
|
||||
<a href="{{ base_url_relative }}/{{ item.route }}">
|
||||
<i class="fa fa-fw {{ item.icon }}"></i> {{ label|tu }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
<li class="{{ (location == 'plugins') ? 'selected' : '' }}">
|
||||
<a href="{{ base_url_relative }}/plugins">
|
||||
<i class="fa fa-fw fa-plug"></i> {{ "PLUGIN_ADMIN.PLUGINS"|tu }}
|
||||
|
||||
Reference in New Issue
Block a user