You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2022-10-25 09:27:47

Florian51
Member
Registered: 2019-02-21
Posts: 23

Generic Object - Add Icon

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

#2 2023-03-16 04:45:12

rafapraz
Member
Registered: 2023-03-15
Posts: 1

Re: Generic Object - Add Icon

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.

genericobject-menu-icon-1.png

The result achieved can be seen in the image below.

genericobject-menu-icon-2.png

Offline

#3 2023-06-11 22:22:30

HoracioDos
Member
Registered: 2023-06-10
Posts: 1

Re: Generic Object - Add Icon

Hello rafapraz.
I can't see your images. How did you change object.class.php?
Thanks!

Offline

#4 2023-06-19 09:27:20

Totem974
Member
Registered: 2023-06-19
Posts: 1

Re: Generic Object - Add Icon

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

#5 2023-09-18 19:58:11

jardel.silva
Member
Registered: 2023-05-03
Posts: 1

Re: Generic Object - Add Icon

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

#6 2024-05-26 07:48:18

pedropablobm
Member
Registered: 2022-07-28
Posts: 4

Re: Generic Object - Add Icon

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


FluxBB bbcode test

Last edited by pedropablobm (2024-05-26 07:50:16)

Offline

#7 Yesterday 16:49:20

boedyirh
Member
Registered: Yesterday
Posts: 1

Re: Generic Object - Add Icon

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

Board footer

Powered by FluxBB