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 2024-04-17 11:36:05

scarletTornado
Member
Registered: 2024-04-12
Posts: 19

[SOLVED]Plugin development: can't add items to custom object

I'm trying to develop a plugin that allows me to create lists of assets. I recently looked into the code of Appliance.php and associated classes, took the code and the database table structure from it, and adapted it for my needs. Still, I'm having no luck as I can't add items to the list object I created. I get the following error:

[2024-04-17 11:05:26] glpiphplog.CRITICAL:   *** Uncaught Exception Error: Class "Assetlist" not found in C:\...\glpi-test\src\CommonDBConnexity.php at line 387
  Backtrace :
  src\CommonDBRelation.php:400                       CommonDBConnexity::canConnexity()
  src\CommonDBRelation.php:593                       CommonDBRelation::canRelation()
  src\CommonDBTM.php:2964                            CommonDBRelation::canCreate()
  src\CommonDBTM.php:3074                            CommonDBTM->can()
  plugins\assetlist\front\assetlist_item.form.php:20 CommonDBTM->check()

Not really sure why it can't find my class as I have already registered all my classes through the following code:

Plugin::registerClass(Assetlist::class);

Last edited by scarletTornado (2024-04-29 15:13:53)

Offline

#2 2024-04-17 15:36:00

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

Re: [SOLVED]Plugin development: can't add items to custom object

Plugin classes must be prefixed if you are not using namespaces. For example, with the "webresources" plugin I have a "PluginWebresourcesResource" class in the "inc/resource.class.php" file. This class and file naming scheme allows GLPI to autoload the class correctly.

https://glpi-developer-documentation.re … jects.html


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 2024-04-19 17:37:36

scarletTornado
Member
Registered: 2024-04-12
Posts: 19

Re: [SOLVED]Plugin development: can't add items to custom object

Thank you again cconard96, I did what you said and edited the classes which extended from CommonDBRelation to correct the type names. I'm only missing how to associate contracts to my custom objects and also allow it to have an impact tab.

Offline

#4 2024-04-19 23:01:13

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

Re: [SOLVED]Plugin development: can't add items to custom object

For impact analysis, you can add something like this in your setup.php init function:
global $CFG_GLPI;
$CFG_GLPI['impact_types'][] = YourCustomClass::class;

I'm not sure if anything else is needed for that.

For contracts, most of the work is already done for you.
You just need to add a Contract_Item tab to your object's form.
Example in your custom object class:
function defineTabs($options = []) {
      $tabs = [];
      $this->addDefaultFormTab($tabs);
      $this->addStandardTab(Contract_Item::class, $tabs, $options);

      return $tabs;
}

The relationship between contracts and your custom objects will be handled by the Contract_Item class and stored in the glpi_contract_items table.
You should also add your custom class to the $CFG_GLPI['contract_types'] array.


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 2024-04-22 09:14:49

scarletTornado
Member
Registered: 2024-04-12
Posts: 19

Re: [SOLVED]Plugin development: can't add items to custom object

Adding my type to the 'contract_types' works out, but the impact tab isn't displaying, I already added it to the 'impact_types' array.

Offline

#6 2024-04-22 10:41:05

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

Re: [SOLVED]Plugin development: can't add items to custom object

Looks like you need to add your plugin's item type in Setup > General on the Impact Analysis tab to enable impact analysis in your GLPI too.


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

#7 2024-04-22 12:57:56

scarletTornado
Member
Registered: 2024-04-12
Posts: 19

Re: [SOLVED]Plugin development: can't add items to custom object

Doesn't appear on list. Quite strange, I thought it would show up after adding it to the 'impact_types' array.

Offline

#8 2024-04-22 14:23:45

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

Re: [SOLVED]Plugin development: can't add items to custom object

Try 'impact_asset_types' instead of 'impact_types' for the $CFG_GLPI array where your class is the key and a path to an icon image is the value.
See inc/define.php in the GLPI code for examples.


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

#9 2024-04-22 15:05:52

scarletTornado
Member
Registered: 2024-04-12
Posts: 19

Re: [SOLVED]Plugin development: can't add items to custom object

Works perfectly now, thank you

Offline

Board footer

Powered by FluxBB