feat: add hook admin menu (#208)

* feat: add hook admin menu

* fix: removing menu sort

* feat: menu order property

* fix: menu order value

* feat: add main menu order
This commit is contained in:
Gabriel Pedro 2022-11-28 13:05:08 -04:00 committed by GitHub
parent acb551c5b0
commit 20638f430a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 28 deletions

View File

@ -1,48 +1,64 @@
<?php
return [
['name' => 'Dashboard', 'icon' => 'tachometer-alt', 'link' => 'dashboard'],
['name' => 'News', 'icon' => 'newspaper', 'link' =>
$menus = [
['name' => 'Dashboard', 'icon' => 'tachometer-alt', 'order' => 10, 'link' => 'dashboard'],
['name' => 'News', 'icon' => 'newspaper', 'order' => 20, 'link' =>
[
['name' => 'View', 'link' => 'news'],
['name' => 'Add news', 'link' => 'news&action=new&type=1'],
['name' => 'Add ticker', 'link' => 'news&action=new&type=2'],
['name' => 'Add article', 'link' => 'news&action=new&type=3'],
['name' => 'View', 'link' => 'news', 'order' => 10],
['name' => 'Add news', 'link' => 'news&action=new&type=1', 'order' => 20],
['name' => 'Add ticker', 'link' => 'news&action=new&type=2', 'order' => 30],
['name' => 'Add article', 'link' => 'news&action=new&type=3', 'order' => 40],
],
],
['name' => 'Changelogs', 'icon' => 'newspaper', 'link' =>
['name' => 'Changelogs', 'icon' => 'newspaper', 'order' => 30, 'link' =>
[
['name' => 'View', 'link' => 'changelog'],
['name' => 'Add', 'link' => 'changelog&action=new'],
['name' => 'View', 'link' => 'changelog', 'order' => 10],
['name' => 'Add', 'link' => 'changelog&action=new', 'order' => 20],
],
],
['name' => 'Mailer', 'icon' => 'envelope', 'link' => 'mailer', 'disabled' => !config('mail_enabled')],
['name' => 'Pages', 'icon' => 'book', 'link' =>
['name' => 'Mailer', 'icon' => 'envelope', 'order' => 40, 'link' => 'mailer', 'disabled' => !config('mail_enabled')],
['name' => 'Pages', 'icon' => 'book', 'order' => 50, 'link' =>
[
['name' => 'View', 'link' => 'pages'],
['name' => 'Add', 'link' => 'pages&action=new'],
['name' => 'View', 'link' => 'pages', 'order' => 10],
['name' => 'Add', 'link' => 'pages&action=new', 'order' => 20],
],
],
['name' => 'Menus', 'icon' => 'list', 'link' => 'menus'],
['name' => 'Plugins', 'icon' => 'plug', 'link' => 'plugins'],
['name' => 'Server Data', 'icon' => 'gavel', 'link' => 'data'],
['name' => 'Editor', 'icon' => 'edit', 'link' =>
['name' => 'Menus', 'icon' => 'list', 'order' => 60, 'link' => 'menus'],
['name' => 'Plugins', 'icon' => 'plug', 'order' => 70, 'link' => 'plugins'],
['name' => 'Server Data', 'icon' => 'gavel', 'order' => 80, 'link' => 'data'],
['name' => 'Editor', 'icon' => 'edit', 'order' => 90, 'link' =>
[
['name' => 'Accounts', 'link' => 'accounts'],
['name' => 'Players', 'link' => 'players'],
['name' => 'Accounts', 'link' => 'accounts', 'order' => 10],
['name' => 'Players', 'link' => 'players', 'order' => 20],
],
],
['name' => 'Tools', 'icon' => 'tools', 'link' =>
['name' => 'Tools', 'icon' => 'tools', 'order' => 100, 'link' =>
[
['name' => 'Notepad', 'link' => 'notepad'],
['name' => 'phpinfo', 'link' => 'phpinfo'],
['name' => 'Notepad', 'link' => 'notepad', 'order' => 10],
['name' => 'phpinfo', 'link' => 'phpinfo', 'order' => 20],
],
],
['name' => 'Logs', 'icon' => 'bug', 'link' =>
['name' => 'Logs', 'icon' => 'bug', 'order' => 110, 'link' =>
[
['name' => 'Logs', 'link' => 'logs'],
['name' => 'Reports', 'link' => 'reports'],
['name' => 'Visitors', 'icon' => 'user', 'link' => 'visitors'],
['name' => 'Logs', 'link' => 'logs', 'order' => 10],
['name' => 'Reports', 'link' => 'reports', 'order' => 20],
['name' => 'Visitors', 'icon' => 'user', 'link' => 'visitors', 'order' => 30],
],
],
];
$hooks->trigger(HOOK_ADMIN_MENU);
usort($menus, function ($a, $b) {
return $a['order'] - $b['order'];
});
foreach ($menus as $i => $menu) {
if (isset($menu['link']) && is_array($menu['link'])) {
usort($menus[$i]['link'], function ($a, $b) {
return $a['order'] - $b['order'];
});
}
}
return $menus;

View File

@ -49,8 +49,9 @@ define('HOOK_ACCOUNT_CREATE_AFTER_TOWNS', ++$i);
define('HOOK_ACCOUNT_CREATE_BEFORE_SUBMIT_BUTTON', ++$i);
define('HOOK_ACCOUNT_CREATE_AFTER_FORM', ++$i);
define('HOOK_ACCOUNT_CREATE_AFTER_SUBMIT', ++$i);
define('HOOK_ADMIN_MENU', ++$i);
define('HOOK_FIRST', HOOK_STARTUP);
define('HOOK_LAST', HOOK_ACCOUNT_CREATE_AFTER_SUBMIT);
define('HOOK_LAST', HOOK_ADMIN_MENU);
require_once LIBS . 'plugins.php';
class Hook