From 8484e55d93f929142f51186a241f2f17c6272877 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Mon, 31 Oct 2022 16:07:47 +0100 Subject: [PATCH] new: [workflowModule:attribute_ids_flag_operation] Module to toggle/remove the to_ids flag --- .../Module_attribute_ids_flag_operation.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 app/Model/WorkflowModules/action/Module_attribute_ids_flag_operation.php diff --git a/app/Model/WorkflowModules/action/Module_attribute_ids_flag_operation.php b/app/Model/WorkflowModules/action/Module_attribute_ids_flag_operation.php new file mode 100644 index 000000000..e25f31051 --- /dev/null +++ b/app/Model/WorkflowModules/action/Module_attribute_ids_flag_operation.php @@ -0,0 +1,61 @@ +params = [ + [ + 'id' => 'action', + 'label' => __('To IDS Flag'), + 'type' => 'select', + 'options' => [ + 'add' => __('Toggle IDS flag'), + 'remove' => __('Remove IDS flag'), + ], + 'default' => 'add', + ], + ]; + } + + public function exec(array $node, WorkflowRoamingData $roamingData, array &$errors = []): bool + { + parent::exec($node, $roamingData, $errors); + $params = $this->getParamsWithValues($node); + + $rData = $roamingData->getData(); + $user = $roamingData->getUser(); + + $matchingItems = $this->getMatchingItemsForAttributes($node, $rData); + if ($matchingItems === false) { + return true; + } + $result = $this->__saveAttribute($matchingItems, $rData, $params, $user); + return $result; + } + + protected function _editAttribute(array $attribute, array $rData, array $params): array + { + if ($params['action']['value'] == 'remove') { + $attribute['to_ids'] = false; + } else { + $attribute['to_ids'] = true; + } + return $attribute; + } +}