From 44fe7d6b57a6c50da087b701126cf17cbde41016 Mon Sep 17 00:00:00 2001 From: Alexandre Delaunay Date: Mon, 10 Jan 2022 11:13:15 +0100 Subject: [PATCH] implements filter_actors hook --- hook.php | 16 ++++++++++++++++ setup.php | 8 ++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hook.php b/hook.php index fd9526b..124f435 100644 --- a/hook.php +++ b/hook.php @@ -686,3 +686,19 @@ function plugin_example_infocom_hook($params) { echo __("Plugin example displays on central page", "example"); echo ""; } + +function plugin_example_filter_actors(array $params = []): array { + $itemtype = $params['params']['itemtype']; + $items_id = $params['params']['items_id']; + + // remove users_id = 1 for assignee list + if ($itemtype == 'Ticket' && $params['params']['actortype'] == 'assign') { + foreach ($params['actors'] as $index => &$actor) { + if ($actor['type'] == 'user' && $actor['items_id'] == 1) { + unset($params['actors'][$index]); + } + } + } + + return $params; +} diff --git a/setup.php b/setup.php index 503f292..5631f7b 100755 --- a/setup.php +++ b/setup.php @@ -31,6 +31,8 @@ // Purpose of file: // ---------------------------------------------------------------------- +use Glpi\Plugin\Hooks; + define ('PLUGIN_EXAMPLE_VERSION', '7.1'); /** @@ -202,13 +204,15 @@ function plugin_init_example() { $PLUGIN_HOOKS['post_item_form']['example'] = ['PluginExampleItemForm', 'postItemForm']; // declare this plugin as an import plugin for Computer itemtype - $PLUGIN_HOOKS['import_item']['exemple'] = ['Computer' => ['Plugin']]; + $PLUGIN_HOOKS['import_item']['example'] = ['Computer' => ['Plugin']]; // add additional informations on Computer::showForm - $PLUGIN_HOOKS['autoinventory_information']['exemple'] = [ + $PLUGIN_HOOKS['autoinventory_information']['example'] = [ 'Computer' => ['PluginExampleComputer', 'showInfo'] ]; + $PLUGIN_HOOKS[Hooks::FILTER_ACTORS]['example'] = "plugin_example_filter_actors"; + }