Skip to content

Instantly share code, notes, and snippets.

@cconard96
Created August 13, 2020 23:03
Show Gist options
  • Save cconard96/5e5710d4fe4e138a1b2d329c46c7f20d to your computer and use it in GitHub Desktop.
Save cconard96/5e5710d4fe4e138a1b2d329c46c7f20d to your computer and use it in GitHub Desktop.
Remove default GLPI dashboard links (Revert to < 9.5 links) and add a new entry for the dashboards.
<?php
function plugin_menu94_install()
{
return true;
}
function plugin_menu94_uninstall()
{
return true;
}
function plugin_menu94_redefine_menus($menu)
{
// Revert Assets default menu option
$menu['assets']['default'] = Computer::getSearchURL(false);
// Add Assistance dashboard link only if the user has rights
if (\Glpi\Dashboard\Dashboard::canView()) {
$menu['assets']['content'][strtolower(\Glpi\Dashboard\Dashboard::class)] = [
'title' => 'Dashboard',
'icon' => 'fas fa-tachometer-alt',
'page' => '/front/dashboard_assets.php',
'links' => ['search' => '/front/dashboard_assets.php']
];
}
// Revert Assistance default menu option
$menu['helpdesk']['default'] = Ticket::getSearchURL(false);
// Add Assistance dashboard link only if the user has rights
if (\Glpi\Dashboard\Dashboard::canView()) {
$menu['helpdesk']['content'][strtolower(\Glpi\Dashboard\Dashboard::class)] = [
'title' => 'Dashboard',
'icon' => 'fas fa-tachometer-alt',
'page' => '/front/dashboard_helpdesk.php',
'links' => ['search' => '/front/dashboard_helpdesk.php']
];
}
return $menu;
}
<?php
define('PLUGIN_MENU94_VERSION', '1.0.0');
define('PLUGIN_MENU94_MIN_GLPI', '9.5.0');
define('PLUGIN_MENU94_MAX_GLPI', '9.6.0');
function plugin_init_menu94() {
global $PLUGIN_HOOKS;
$PLUGIN_HOOKS['csrf_compliant']['menu94'] = true;
$PLUGIN_HOOKS['redefine_menus']['menu94'] = 'plugin_menu94_redefine_menus';
}
function plugin_version_menu94() {
return [
'name' => '9.4 Style Menu',
'version' => PLUGIN_MENU94_VERSION,
'author' => 'Curtis Conard',
'license' => 'GPLv2',
'homepage'=>'https://github.com/cconard96/',
'requirements' => [
'glpi' => [
'min' => PLUGIN_MENU94_MIN_GLPI,
'max' => PLUGIN_MENU94_MAX_GLPI
]
]
];
}
function plugin_menu94_check_prerequisites() {
if (!method_exists('Plugin', 'checkGlpiVersion')) {
$version = preg_replace('/^((\d+\.?)+).*$/', '$1', GLPI_VERSION);
$matchMinGlpiReq = version_compare($version, PLUGIN_MENU94_MIN_GLPI, '>=');
$matchMaxGlpiReq = version_compare($version, PLUGIN_MENU94_MAX_GLPI, '<');
if (!$matchMinGlpiReq || !$matchMaxGlpiReq) {
echo vsprintf(
'This plugin requires GLPI >= %1$s and < %2$s.',
[
PLUGIN_MENU94_MIN_GLPI,
PLUGIN_MENU94_MAX_GLPI,
]
);
return false;
}
}
return true;
}
function plugin_menu94_check_config()
{
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment