Skip to content

Commit d18852c

Browse files
committed
fix(glpiselectfield): generic objects support lost in TWIG conversion
1 parent 6309aa3 commit d18852c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

inc/question.class.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,28 @@ public static function dropdownObjectSubType(string $name, array $options = []):
13351335
$optgroup[__("Assets")][PluginDatabasesDatabase::class] = PluginDatabasesDatabase::getTypeName(2) . ' (' . _n('Plugin', 'Plugins', 1) . ')';
13361336
}
13371337

1338+
// Get additional itemtypes from plugins
1339+
$additionalTypes = Plugin::doHookFunction('formcreator_get_glpi_object_types', []);
1340+
// Cleanup data from plugins
1341+
$cleanedAditionalTypes = [];
1342+
foreach ($additionalTypes as $groupName => $itemtypes) {
1343+
if (!is_string($groupName)) {
1344+
continue;
1345+
}
1346+
$cleanedAditionalTypes[$groupName] = [];
1347+
foreach ($itemtypes as $itemtype => $typeName) {
1348+
if (!class_exists($itemtype)) {
1349+
continue;
1350+
}
1351+
if (array_search($itemtype, $cleanedAditionalTypes[$groupName])) {
1352+
continue;
1353+
}
1354+
$cleanedAditionalTypes[$groupName][$itemtype] = $typeName;
1355+
}
1356+
}
1357+
// Merge new itemtypes to predefined ones
1358+
$optgroup = array_merge_recursive($optgroup, $cleanedAditionalTypes);
1359+
13381360
$itemtype = is_subclass_of($options['value'], CommonDBTM::class) ? $options['value'] : '';
13391361
Dropdown::showFromArray($name, $optgroup, [
13401362
'value' => $itemtype,

0 commit comments

Comments
 (0)