You are not logged in.
Hello,
Do you know if it is possible or if there is a way to add an icon on a generic object as for the Computers menu for example ?
Thanks for help.
Offline
Hello,
Recently I came across the same problem and I opted to use the comment field of the generic object to define the menu icon. For that, I needed to change the object.class.php file, as shown in the image below.
The result achieved can be seen in the image below.
Offline
Hello rafapraz.
I can't see your images. How did you change object.class.php?
Thanks!
Offline
Hi, i'm trying to do the same thing (add icon to custom generic object).
$menu[$str_name]['icon'] = ($type['comment'] == '') ? $type['itemtype']::getIcon() : $type['comment'];
&&
'icon' => ($type['comment'] == '') ? $type['itemtype']::getIcon() : $type['comment'],
Did try to add code from your screenshot changing object.class.php, but how to specify where is the .svg icon for getIcon ?
Last edited by Totem974 (2023-06-19 09:28:18)
Offline
Hello Rafa, I'm Brazilian too, I would like to know in detail how you added the space in the name of the item and how you added the icon, please.
Olá rafa, sou brasileiro também, gostaria de saber em detalhes como voce adicionou o espaço no nome do item e como adicionou o ícone por gentileza.
Offline
Hola.
El código tal como está me funciona. Muchas gracias.
A los que no les funciona deben crear una carpeta /glpi/marketplace/genericobject/impact_icons y colocar alli los archivos svg . Descarguen de openclipart.org.
Adjunto como debe quedar.
En comentarios colocan solo el nombre del archivo, en mi caso se llama laptop.svg
fas fa-laptop
Last edited by pedropablobm (2024-05-26 07:50:16)
Offline
You can change public static function getMenuContent (around line 1260) in file glpi/marketplace/genericobject/inc/object.class.php
with this function.
You may add your icon here. Here I have 5 icons, but you are free to add another icon.
$icons_collection = ['ti ti-layout-navbar', 'ti ti-printer', 'ti ti-plug', 'ti ti-packages', 'ti ti-server'];
=======
public static function getMenuContent()
{
$icons_collection = ['ti ti-layout-navbar', 'ti ti-printer', 'ti ti-plug', 'ti ti-packages', 'ti ti-server'];
$types = PluginGenericobjectType::getTypes();
$index_icon =0;
$menu = [];
foreach ($types as $type) {
$itemtype = $type['itemtype'];
if (!class_exists($itemtype)) {
continue;
}
$item = new $itemtype();
$itemtype_rightname = PluginGenericobjectProfile::getProfileNameForItemtype($itemtype);
if (
class_exists($itemtype)
&& Session::haveRight($itemtype_rightname, READ)
) {
$links = [];
$links['search'] = $itemtype::getSearchUrl(false);
$links['lists'] = '';
if ($item->canUseTemplate()) {
$links['template'] = "/front/setup.templates.php?itemtype=$itemtype&add=0";
if (Session::haveRight($itemtype_rightname, CREATE)) {
$links['add'] = "/front/setup.templates.php?itemtype=$itemtype&add=1";
}
} else {
if (Session::haveRight($itemtype_rightname, CREATE)) {
$links['add'] = $itemtype::getFormUrl(false);
}
}
if (
$type['plugin_genericobject_typefamilies_id'] > 0
&& (!isset($_GET['itemtype'])
|| !preg_match("/itemtype=" . $_GET['itemtype'] . "/", $_GET['itemtype']))
) {
$family_id = $type['plugin_genericobject_typefamilies_id'];
$name = Dropdown::getDropdownName("glpi_plugin_genericobject_typefamilies", $family_id, 0, false);
$str_name = strtolower($name);
$menu[$str_name]['title'] = Dropdown::getDropdownName("glpi_plugin_genericobject_typefamilies", $family_id);
$menu[$str_name]['icon'] = $icons_collection[$index_icon];
$menu[$str_name]['page'] = '/' . Plugin::getWebDir('genericobject', false) . '/front/familylist.php?id=' . $family_id;
$menu[$str_name]['options'][strtolower($itemtype)] = [
'title' => $type['itemtype']::getMenuName(),
'page' => $itemtype::getSearchUrl(false),
'icon' => $icons_collection[$index_icon],
'links' => $links,
'lists_itemtype' => $itemtype,
];
$index_icon++;
} else {
$menu[strtolower($itemtype)] = [
'title' => $type['itemtype']::getMenuName(),
'page' => $itemtype::getSearchUrl(false),
'icon' => $icons_collection[$index_icon],
'links' => $links,
'lists_itemtype' => $itemtype,
];
$index_icon++;
}
}
}
// Sort by menu entries name
uasort($menu, fn($a, $b) => $a['title'] <=> $b['title']);
// Mark as multi entries
$menu['is_multi_entries'] = true;
return $menu;
}
Last edited by boedyirh (Today 02:12:11)
Offline