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 2023-06-30 19:41:06

Johan Romo
Member
From: Mexico City
Registered: 2022-10-27
Posts: 13

[SOLVED] PHP Display plugin only to certain enities

Hi everyone.

I am coding a plugin that adds a new tab into glpi tickets page, we work with a lot of entities and I want to display this plugin to only tickets from certain entities.

How can I achieve it?

Inside my PluginClass I have the function getabNameForItem and displayTabContentForItem, my idea is to write them inside an if condition, and the value to check is the ticket's entity, but I cannot get this entity ID.

<?php

class PluginClass extends CommonGLPI
{

     /*Just to display if ticket's entity ID is equal to 1*/
     if( ticket_entity_id == 1 )
     {
         /**
         * This function is called from GLPI to allow the plugin to insert one or more item
         *  inside the left menu of a Itemtype.
         */
        function getTabNameForItem(CommonGLPI $item, $withtemplate=0)
       {
            return self::createTabEntry('Nuevo Tab para cargar informacion');
       }
 
        /**
        * This function is called from GLPI to render the form when the user click
        *  on the menu item generated from getTabNameForItem()
        */
        public static function displayTabContentForItem(CommonGLPI $item, $tabnum=1, $withtemplate=0)
        {
           ALL MY CODE
        }

    }

?>

Thank you

Last edited by Johan Romo (2023-09-15 19:43:52)

Offline

#2 2023-07-01 17:08:54

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: [SOLVED] PHP Display plugin only to certain enities

PHP doesn't support function definitions inside IF statements.
You need to do this check inside both tab functions.
If you want to hide the tab, you can return "false" in getTabNameForItem.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#3 2023-07-04 19:13:08

Johan Romo
Member
From: Mexico City
Registered: 2022-10-27
Posts: 13

Re: [SOLVED] PHP Display plugin only to certain enities

Thank you cconard96

Another question, How can I get the ticket's entity?

Greatings.

Offline

#4 2023-07-06 01:50:35

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: [SOLVED] PHP Display plugin only to certain enities

$item->getEntityID();


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#5 2023-07-06 18:02:06

Johan Romo
Member
From: Mexico City
Registered: 2022-10-27
Posts: 13

Re: [SOLVED] PHP Display plugin only to certain enities

Thank you smile

I only have another question, Is there any documentation where can I read information about glpi object's methods?

For example, I did not know about the method getEntityID() for $item, so, it would be very useful to know more about them.

Last edited by Johan Romo (2023-07-06 18:02:41)

Offline

#6 2023-07-08 13:32:34

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,813
Website

Re: [SOLVED] PHP Display plugin only to certain enities

There is no comprehensive documentation pre-generated. Any proper IDE with support for PHP (including VSCode with the right extensions) would make method discovery 100x easier.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

Board footer

Powered by FluxBB