Skip to content

Commit

Permalink
fix(glpiselectfield): generic objects support lost in TWIG conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed May 9, 2022
1 parent 6309aa3 commit d18852c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions inc/question.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,28 @@ public static function dropdownObjectSubType(string $name, array $options = []):
$optgroup[__("Assets")][PluginDatabasesDatabase::class] = PluginDatabasesDatabase::getTypeName(2) . ' (' . _n('Plugin', 'Plugins', 1) . ')';
}

// Get additional itemtypes from plugins
$additionalTypes = Plugin::doHookFunction('formcreator_get_glpi_object_types', []);
// Cleanup data from plugins
$cleanedAditionalTypes = [];
foreach ($additionalTypes as $groupName => $itemtypes) {
if (!is_string($groupName)) {
continue;
}
$cleanedAditionalTypes[$groupName] = [];
foreach ($itemtypes as $itemtype => $typeName) {
if (!class_exists($itemtype)) {
continue;
}
if (array_search($itemtype, $cleanedAditionalTypes[$groupName])) {
continue;
}
$cleanedAditionalTypes[$groupName][$itemtype] = $typeName;
}
}
// Merge new itemtypes to predefined ones
$optgroup = array_merge_recursive($optgroup, $cleanedAditionalTypes);

$itemtype = is_subclass_of($options['value'], CommonDBTM::class) ? $options['value'] : '';
Dropdown::showFromArray($name, $optgroup, [
'value' => $itemtype,
Expand Down

0 comments on commit d18852c

Please sign in to comment.