mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2026-05-06 08:05:33 +02:00
Updated navigation menu to be fully controlled and overrideable by onAdminMenu event
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
1. [](#improved)
|
||||
* Optimized admin for speed (only load frontend pages on demand)
|
||||
* Updated navigation menu to be fully controlled and overrideable by `onAdminMenu` event
|
||||
|
||||
# v1.10.0-beta.5
|
||||
## 08/11/2019
|
||||
|
||||
67
admin.php
67
admin.php
@@ -28,6 +28,7 @@ use Grav\Plugin\Admin\AdminController;
|
||||
use Grav\Plugin\Admin\Twig\AdminTwigExtension;
|
||||
use Grav\Plugin\Form\Form;
|
||||
use Grav\Plugin\Login\Login;
|
||||
use Pimple\Container;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
|
||||
class AdminPlugin extends Plugin
|
||||
@@ -603,8 +604,14 @@ class AdminPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
// Gather Plugin-hooked nav items
|
||||
// Gather all nav items
|
||||
$this->grav['twig']->plugins_hooked_nav = [];
|
||||
$this->grav->fireEvent('onAdminMenu');
|
||||
uasort($this->grav['twig']->plugins_hooked_nav, function ($a, $b) {
|
||||
$ac = $a['priority'] ?? 0;
|
||||
$bc = $b['priority'] ?? 0;
|
||||
return $bc <=> $ac;
|
||||
});
|
||||
|
||||
switch ($this->template) {
|
||||
case 'dashboard':
|
||||
@@ -721,6 +728,63 @@ class AdminPlugin extends Plugin
|
||||
$admin->addPermissions($permissions);
|
||||
}
|
||||
|
||||
public function onAdminMenu()
|
||||
{
|
||||
// Dashboard
|
||||
$this->grav['twig']->plugins_hooked_nav['PLUGIN_ADMIN.DASHBOARD'] = [
|
||||
'route' => 'dashboard',
|
||||
'icon' => 'fa-th',
|
||||
'authorize' => ['admin.login', 'admin.super'],
|
||||
'priority' => 10
|
||||
];
|
||||
|
||||
// Configuration
|
||||
$this->grav['twig']->plugins_hooked_nav['PLUGIN_ADMIN.CONFIGURATION'] = [
|
||||
'route' => 'config',
|
||||
'icon' => 'fa-wrench',
|
||||
'authorize' => ['admin.configuration_system', 'admin.super'],
|
||||
'priority' => 9
|
||||
];
|
||||
|
||||
// Pages
|
||||
$count = new Container(['count' => function () { return $this->admin->pagesCount(); }]);
|
||||
$this->grav['twig']->plugins_hooked_nav['PLUGIN_ADMIN.PAGES'] = [
|
||||
'route' => 'pages',
|
||||
'icon' => 'fa-file-text-o',
|
||||
'authorize' => ['admin.pages', 'admin.super'],
|
||||
'badge' => $count,
|
||||
'priority' => 5
|
||||
];
|
||||
|
||||
// Plugins
|
||||
$count = new Container(['updates' => 0, 'count' => function () { return count($this->admin->plugins()); }]);
|
||||
$this->grav['twig']->plugins_hooked_nav['PLUGIN_ADMIN.PLUGINS'] = [
|
||||
'route' => 'plugins',
|
||||
'icon' => 'fa-plug',
|
||||
'authorize' => ['admin.plugins', 'admin.super'],
|
||||
'badge' => $count,
|
||||
'priority' => -8
|
||||
];
|
||||
|
||||
// Themes
|
||||
$count = new Container(['updates' => 0, 'count' => function () { return count($this->admin->themes()); }]);
|
||||
$this->grav['twig']->plugins_hooked_nav['PLUGIN_ADMIN.THEMES'] = [
|
||||
'route' => 'themes',
|
||||
'icon' => 'fa-tint',
|
||||
'authorize' => ['admin.themes', 'admin.super'],
|
||||
'badge' => $count,
|
||||
'priority' => -9
|
||||
];
|
||||
|
||||
// Tools
|
||||
$this->grav['twig']->plugins_hooked_nav['PLUGIN_ADMIN.TOOLS'] = [
|
||||
'route' => 'tools',
|
||||
'icon' => 'fa-briefcase',
|
||||
'authorize' => $this->admin::toolsPermissions(),
|
||||
'priority' => -10
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current route is under the admin path
|
||||
*
|
||||
@@ -830,6 +894,7 @@ class AdminPlugin extends Plugin
|
||||
'onOutputGenerated' => ['onOutputGenerated', 0],
|
||||
'onAdminAfterSave' => ['onAdminAfterSave', 0],
|
||||
'onAdminData' => ['onAdminData', 0],
|
||||
'onAdminMenu' => ['onAdminMenu', 1000],
|
||||
]);
|
||||
|
||||
// Check for required plugins
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
{% extends 'partials/base.html.twig' %}
|
||||
|
||||
{% set config_slug = uri.basename|e %}
|
||||
{% set config_slug = uri.basename %}
|
||||
{% if config_slug == 'config' %}
|
||||
{% set config_slug = authorize(['admin.configuration_system','admin.super']) ? 'system' : 'site' %}
|
||||
{% endif %}
|
||||
{% set isInfo = (config_slug == 'info') %}
|
||||
|
||||
{% set tab_title_string = "PLUGIN_ADMIN." ~ config_slug|upper %}
|
||||
|
||||
@@ -15,75 +15,23 @@
|
||||
|
||||
<div class="admin-menu-wrapper">
|
||||
<ul id="admin-menu">
|
||||
<li class="{{ (location == 'dashboard') ? 'selected' : '' }}">
|
||||
<a href="{{ base_url_relative }}"><i class="fa fa-fw fa-th"></i><em>{{ "PLUGIN_ADMIN.DASHBOARD"|tu }}</em></a>
|
||||
</li>
|
||||
{% if authorize(['admin.configuration', 'admin.super']) %}
|
||||
<li class="{{ (location == 'system' or location == 'site' or location == 'config') ? 'selected' : '' }}">
|
||||
<a href="{{ base_url_relative }}/config/{{ authorize(['admin.configuration_system','admin.super']) ? 'system' : 'site' }}"><i class="fa fa-fw fa-wrench"></i><em>{{ "PLUGIN_ADMIN.CONFIGURATION"|tu }}</em></a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if authorize(['admin.pages', 'admin.super']) %}
|
||||
<li class="{{ (location == 'pages') ? 'selected' : '' }}">
|
||||
<a href="{{ base_url_relative }}/pages">
|
||||
<i class="fa fa-fw fa-file-text-o"></i>
|
||||
<em>{{ "PLUGIN_ADMIN.PAGES"|tu }}</em>
|
||||
<span class="badges">
|
||||
<span class="badge count">{{ admin.pagesCount }}</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if grav.twig.plugins_hooked_nav %}
|
||||
{% for label, item in grav.twig.plugins_hooked_nav %}
|
||||
{% if authorize((item.authorize is defined and item.authorize is iterable) ? item.authorize : [item.authorize ?: ('admin.' ~ (item.location ?: item.route)), 'admin.super']) %}
|
||||
<li class="{{ (location == (item.location ?: item.route)) ? 'selected' : '' }}">
|
||||
<a href="{{ base_url_relative }}/{{ item.route ?: item.location }}">
|
||||
<i class="fa fa-fw {{ item.icon }}"></i>
|
||||
<em>{{ label|tu }}</em>
|
||||
{% if item.badge %}
|
||||
<span class="badges {% if item.badge.updates is defined %}with-updates{% endif %}">
|
||||
{% if item.badge.updates is defined %}<span class="badge updates">{{ item.badge.updates }}</span>{% endif %}
|
||||
<span class="badge count">{{ item.badge.count }}</span>
|
||||
</span>
|
||||
{% endif %}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if authorize(['admin.plugins', 'admin.super']) %}
|
||||
<li class="{{ (location == 'plugins') ? 'selected' : '' }}">
|
||||
<a href="{{ base_url_relative }}/plugins">
|
||||
<i class="fa fa-fw fa-plug"></i>
|
||||
<em>{{ "PLUGIN_ADMIN.PLUGINS"|tu }}</em>
|
||||
<span class="badges">
|
||||
<span class="badge updates"></span>
|
||||
<span class="badge count">{{ admin.plugins|length }}</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if authorize(['admin.themes', 'admin.super']) %}
|
||||
<li class="{{ (location == 'themes') ? 'selected' : '' }}">
|
||||
<a href="{{ base_url_relative }}/themes">
|
||||
<i class="fa fa-fw fa-tint"></i>
|
||||
<em>{{ "PLUGIN_ADMIN.THEMES"|tu }}</em>
|
||||
<span class="badges">
|
||||
<span class="badge updates"></span>
|
||||
<span class="badge count">{{ admin.themes|length }}</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if authorize(admin.toolsPermissions) %}
|
||||
<li class="{{ (location == 'tools') ? 'selected' : '' }}">
|
||||
<a href="{{ base_url_relative }}/tools">
|
||||
<i class="fa fa-fw fa-briefcase"></i>
|
||||
<em>{{ "PLUGIN_ADMIN.TOOLS"|tu }}</em>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% for label, item in grav.twig.plugins_hooked_nav %}
|
||||
{% if authorize((item.authorize is defined and item.authorize is iterable) ? item.authorize : [item.authorize ?: ('admin.' ~ (item.location ?: item.route)), 'admin.super']) %}
|
||||
<li class="{{ (location == (item.location ?: item.route)) ? 'selected' : '' }}">
|
||||
<a href="{{ base_url_relative }}/{{ item.route ?: item.location }}">
|
||||
<i class="fa fa-fw {{ item.icon }}"></i>
|
||||
<em>{{ label|tu }}</em>
|
||||
{% set badge = item.badge ?? null %}
|
||||
{% if badge %}
|
||||
<span class="badges {% if badge.updates is defined %}with-updates{% endif %}">
|
||||
{% if badge.updates is defined %}<span class="badge updates">{{ badge.updates ?: '' }}</span>{% endif %}
|
||||
<span class="badge count">{{ badge.count }}</span>
|
||||
</span>
|
||||
{% endif %}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% include 'partials/nav-pro.html.twig' ignore missing %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user