From f9a23b6466087f42b404ee7e767f0b00631dd5f9 Mon Sep 17 00:00:00 2001 From: Adrien Clairembault <42734840+AdrienClairembault@users.noreply.github.com> Date: Thu, 24 Nov 2022 10:36:34 +0100 Subject: [PATCH] feat(question): new hooks for other plugins interaction (#3093) --- inc/abstractfield.class.php | 8 +++ inc/abstractitiltarget.class.php | 99 ++++++++++++++++++++++++----- inc/plugintargetinterface.class.php | 47 ++++++++++++++ inc/target_actor.class.php | 18 +++++- js/scripts.js | 49 +------------- 5 files changed, 157 insertions(+), 64 deletions(-) create mode 100644 inc/plugintargetinterface.class.php diff --git a/inc/abstractfield.class.php b/inc/abstractfield.class.php index b91edce22..f388c33eb 100644 --- a/inc/abstractfield.class.php +++ b/inc/abstractfield.class.php @@ -96,9 +96,17 @@ public function show(string $domain, bool $canEdit = true): string { continue; } } + $description = Plugin::doHookFunction('formcreator_question_description', [ + 'description' => $description, + 'question' => $this->getQuestion() + ])['description']; $html .= '
' . html_entity_decode(__($description, $domain)) . '
'; } $html .= '
'; + $this->value = Plugin::doHookFunction('formcreator_question_default_value', [ + 'value' => $this->value, + 'question' => $this->getQuestion() + ])['value']; $html .= $this->getRenderedHtml($domain, $canEdit); $html .= '
'; diff --git a/inc/abstractitiltarget.class.php b/inc/abstractitiltarget.class.php index a1a5fbf75..3fc5cca1f 100644 --- a/inc/abstractitiltarget.class.php +++ b/inc/abstractitiltarget.class.php @@ -437,7 +437,7 @@ protected function setTargetUrgency($data, $formanswer) { * find all actors and prepare data for the ticket being created */ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorFormAnswer $formanswer) { - global $DB; + global $DB, $PLUGIN_HOOKS; $rows = $DB->request([ 'FROM' => PluginFormcreatorTarget_Actor::getTable(), @@ -586,6 +586,26 @@ protected function prepareActors(PluginFormcreatorForm $form, PluginFormcreatorF $this->addActor(PluginFormcreatorTarget_Actor::ACTOR_ROLE_SUPPLIER, $userId, $notify); } break; + default: + foreach (($PLUGIN_HOOKS['formcreator_actors_type'] ?? []) as $plugin => $classes) { + foreach ($classes as $plugin_target) { + if (!is_a($plugin_target, PluginFormcreatorPluginTargetInterface::class, true)) { + continue; + } + if ($actor['actor_type']== $plugin_target::getId()) { + $value = $plugin_target::getActorId($formanswer, $actor['actor_value']); + if ($value) { + if ($plugin_target::getActorType() == PluginFormcreatorPluginTargetInterface::ACTOR_TYPE_USER) { + $this->addActor($actor['actor_role'], $value, $notify); + } else if (PluginFormcreatorPluginTargetInterface::ACTOR_TYPE_GROUP) { + $this->addGroupActor($actor['actor_role'], $value); + } + } + break 2; + } + } + } + break; } } } @@ -1760,7 +1780,7 @@ protected function showActorSettingsHeader($type) { * @return void */ protected function showActorSettingsForType($actorType, array $actors) { - global $DB; + global $DB, $PLUGIN_HOOKS; $itemActor = new PluginFormcreatorTarget_Actor(); $dropdownItems = ['' => Dropdown::EMPTY_VALUE] + $itemActor::getEnumActorType(); @@ -1799,7 +1819,7 @@ protected function showActorSettingsForType($actorType, array $actors) { ] ); - echo '