Skip to content

Commit ea13dd1

Browse files
committed
Register active custom asset definitions as orderable itemtypes (GLPI 11)
GLPI 11 introduced native custom assets defined via Setup → Asset definitions. The plugin's hardcoded $ORDER_TYPES array in plugin_init_order() does not include them, so custom asset classes never appear in the Item type dropdown when creating a new Product reference, making it impossible to order anything based on a custom asset definition. This commit adds an auto-registration loop that, after the existing hardcoded itemtypes, iterates active custom asset definitions via AssetDefinitionManager and appends each generated class name to $ORDER_TYPES if not already present. bootDefinitions() is called explicitly because the manager is instantiated but not yet booted at plugin_init_order() time, so getDefinitions() would otherwise return an empty array. The class_exists() guard makes the block a no-op on GLPI <= 10.x, preserving backward compatibility. Tested on GLPI 11.0.6, PHP 8.3, with custom asset definitions on two independent installations with different capacity sets: - Custom asset appears in Product reference Item type dropdown. - Type and Model dropdowns populate correctly via the existing itemtype + 'Type' / + 'Model' class name convention. - Order validation, item delivery, Generate item massive action, and Reception flow all complete successfully end to end. - The existing AssignableItem handling from #560 already works correctly with custom asset classes once they are registered as orderable itemtypes.
1 parent 43f4e95 commit ea13dd1

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [unreleased]
99

10+
### Added
11+
- Register active GLPI 11 custom asset definitions as orderable itemtypes
12+
1013
### Fixed
1114

1215
- Fix generate associated item massive action

setup.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ function plugin_init_order()
125125
'Pdu',
126126
];
127127

128+
129+
// Auto-register all active custom assets defined via Asset definitions (GLPI 11+)
130+
if (class_exists(\Glpi\Asset\AssetDefinitionManager::class)) {
131+
$asset_manager = \Glpi\Asset\AssetDefinitionManager::getInstance();
132+
$asset_manager->bootDefinitions();
133+
foreach ($asset_manager->getDefinitions(true) as $definition) {
134+
$custom_asset_class = $definition->getAssetClassName();
135+
if (!in_array($custom_asset_class, $ORDER_TYPES, true)) {
136+
$ORDER_TYPES[] = $custom_asset_class;
137+
}
138+
}
139+
}
140+
128141
$CFG_GLPI['plugin_order_types'] = $ORDER_TYPES;
129142

130143
$PLUGIN_HOOKS['pre_item_purge']['order'] = [

0 commit comments

Comments
 (0)