New hook : enable choosing the icon of an item in impact analysis
Add a new hook to enable changing the icon of an item in the impact anlysis.
| Q | A |
|---|---|
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets |
Why not just completing/altering
$CFG_GLPI["default_impact_asset_types"]? I'm not sure a hook is necessary here
It would be possible to change it in the plugin setup.php file by getting the request parameters, however I feel like having a dedicated hook make things clearer. Adding to that, I was thinking of modifying ajax/impact.php & impact.js so that the icons shown in the search result sidebar go through the same treatment, so that the search preview would match the actual icons which will be loaded.
Why not just completing/altering
$CFG_GLPI["default_impact_asset_types"]? I'm not sure a hook is necessary here
Hello Alexandre. This hook permets to define icons for specific types (example : Firewall, Router, Wifi access point) and not only define icons for an global itemtype (as picture for models of objects)
Why not just completing/altering
$CFG_GLPI["default_impact_asset_types"]? I'm not sure a hook is necessary hereHello Alexandre. This hook permets to define icons for specific types (example : Firewall, Router, Wifi access point) and not only define icons for an global itemtype (as picture for models of objects)
Indeed, it may permit to define a specific icon for each different item. As it introduces extra queries (each displayed item is loaded, and impact graph may contains many items, it would be preferable to pass the itemtype and the items_id of the item to the hook instead of loading it. Indeed, it is probable that in most cases, the loading of the item by the plugin would be required only on specific cases (also, the plugin may use a caching system to improve the performances).
I changed the target to main branch, as it introduces a new feature.
Why not just completing/altering
$CFG_GLPI["default_impact_asset_types"]? I'm not sure a hook is necessary hereHello Alexandre. This hook permets to define icons for specific types (example : Firewall, Router, Wifi access point) and not only define icons for an global itemtype (as picture for models of objects)
Indeed, it may permit to define a specific icon for each different item. As it introduces extra queries (each displayed item is loaded, and impact graph may contains many items, it would be preferable to pass the
itemtypeand theitems_idof the item to the hook instead of loading it. Indeed, it is probable that in most cases, the loading of the item by the plugin would be required only on specific cases (also, the plugin may use a caching system to improve the performances).
Updated the code accordingly : the hook is moved with the ones expecting an array as parameters, and the array contains the keys 'itemtype' and 'items_id' (0 in case of the default icon for the sidebar).
Nevermind, OK for me.
Can you add a test ?
What kind of test would you like to be added ? Check the type of the image value (string) and detailed content (valid filepath) ?
Nevermind, OK for me. Can you add a test ?
What kind of test would you like to be added ? Check the type of the image value (string) and detailed content (valid filepath) ?
I take a look on the code and it seems that adding a test for this hook in the test suite is a bit complicated.
I will try to validate this new hook ASAP.
Tested with https://github.com/pluginsGLPI/example/pull/55.