Skip to content

Commit

Permalink
feat(glpiselectfield): hook to allow plugins to declare their itemtypes
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed May 27, 2021
1 parent ff17072 commit 5e70953
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions inc/field/glpiselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,29 @@ public function getDesignSpecializationField(): array {
if ((new Plugin())->isActivated('databases')) {
$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);

array_unshift($optgroup, '---');
$field = Dropdown::showFromArray('glpi_objects', $optgroup, [
'value' => $this->question->fields['values'],
Expand Down

0 comments on commit 5e70953

Please sign in to comment.