diff --git a/front/container.form.php b/front/container.form.php index b8dd3bca..90d244f7 100644 --- a/front/container.form.php +++ b/front/container.form.php @@ -55,6 +55,17 @@ } elseif (isset($_POST['update_fields_values'])) { $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $_POST['plugin_fields_containers_id']); if ($right > READ) { + $containerID = $_POST['plugin_fields_containers_id']; + $data = []; + foreach ($_REQUEST as $key => $value) { + // if key starts with plugin_fields__ remove the prefix + if (strpos($key, "plugin_fields_{$containerID}_") === 0) { + $new_key = substr($key, strlen("plugin_fields_{$containerID}_")); + $data[$new_key] = $value; + } else { + $data[$key] = $value; + } + } $container->updateFieldsValues($_REQUEST, $_REQUEST['itemtype'], false); } Html::back(); diff --git a/inc/container.class.php b/inc/container.class.php index d8cc983f..5c77249f 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -557,22 +557,6 @@ public function prepareInputForAdd($input) $input['itemtypes'] = [$input['itemtypes']]; } - if ($input['type'] === 'dom') { - //check for already exist dom container with this itemtype - $found = $this->find(['type' => 'dom']); - if (count($found) > 0) { - foreach (array_column($found, 'itemtypes') as $founditemtypes) { - foreach (json_decode($founditemtypes) as $founditemtype) { - if (in_array($founditemtype, $input['itemtypes'])) { - Session::AddMessageAfterRedirect(__("You cannot add several blocks with type 'Insertion in the form' on same object", 'fields'), false, ERROR); - - return false; - } - } - } - } - } - if ($input['type'] === 'domtab') { //check for already exist domtab container with this itemtype on this tab $found = $this->find(['type' => 'domtab', 'subtype' => $input['subtype']]); @@ -1604,6 +1588,90 @@ public static function findContainer($itemtype, $type = 'tab', $subtype = '') return $id; } + public static function findContainers($itemtype, $type = 'tab', $subtype = '', $itemId = '') + { + /** @var DBmysql $DB */ + global $DB; + $ids = []; + + if (!empty($itemtype) && !empty($itemId) && class_exists($itemtype)) { + + $obj = new $itemtype(); + if ($obj->getFromDB($itemId)) { + + $entityId = $obj->fields['entities_id'] ?? 0; + $entityIds = getAncestorsOf("glpi_entities", $entityId); + $entityIds[] = $entityId; // Add entity obj itself to the list + $glpiActiveEntities = $_SESSION['glpiactiveentities'] ?? 0; + + $entityRestriction = getEntitiesRestrictCriteria('', '', $glpiActiveEntities, true, true); + + $where = [ + 'is_active' => 1, + 'type' => $type, + new \QueryExpression("JSON_CONTAINS(itemtypes, " . $DB->quote('"' . $itemtype . '"') . ")"), + 'AND' => [ + 'OR' => [ + [ + 'is_recursive' => 1, + 'entities_id' => $entityIds, + ], + [ + 'is_recursive' => 0, + ], + ], + ], + ]; + + if ($subtype !== '') { + if ($subtype === $itemtype . '$main') { + $where['type'] = 'dom'; + } else { + $where['type'] = ['!=', 'dom']; + $where['subtype'] = $subtype; + } + } else { + $where['type'] = $type; + } + + if (!empty($entityRestriction)) { + $allowedEntities = []; + foreach ($entityRestriction as $restriction) { + if (isset($restriction['entities_id']) && is_array($restriction['entities_id'])) { + $allowedEntities = array_merge($allowedEntities, $restriction['entities_id']); + } + } + if (!empty($allowedEntities)) { + $where['entities_id'] = $allowedEntities; + } + } + + $iterator = $DB->request([ + 'SELECT' => 'id', + 'FROM' => self::getTable(), + 'WHERE' => $where, + ]); + + foreach ($iterator as $row) { + $containerId = (int) $row['id']; + + //profiles restriction + if (isset($_SESSION['glpiactiveprofile']['id'])) { + $profileId = $_SESSION['glpiactiveprofile']['id']; + $right = PluginFieldsProfile::getRightOnContainer($profileId, $containerId); + if ($right < READ) { + continue; + } + } + + $ids[] = $containerId; + } + } + } + + return $ids; + } + /** * Post item hook for add * Do store data in db @@ -1614,18 +1682,20 @@ public static function findContainer($itemtype, $type = 'tab', $subtype = '') */ public static function postItemAdd(CommonDBTM $item) { - if (array_key_exists('_plugin_fields_data', $item->input)) { - $data = $item->input['_plugin_fields_data']; - $data['items_id'] = $item->getID(); - $data['entities_id'] = $item->isEntityAssign() ? $item->getEntityID() : 0; - //update data - $container = new self(); - if ($container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction']))) { - return true; - } + if (array_key_exists('_plugin_fields_data_multi', $item->input)) { + $dataMulti = $item->input['_plugin_fields_data_multi']; + foreach ($dataMulti as $data) { + $data['items_id'] = $item->getID(); + $data['entities_id'] = $item->isEntityAssign() ? $item->getEntityID() : 0; + //update data + $container = new self(); + if ($container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction']))) { + continue; + }; - $item->input = []; - return $item; + $item->input = []; + continue; + } } return true; @@ -1642,23 +1712,22 @@ public static function postItemAdd(CommonDBTM $item) public static function preItemUpdate(CommonDBTM $item) { self::preItem($item); - if (array_key_exists('_plugin_fields_data', $item->input)) { - $data = $item->input['_plugin_fields_data']; - $data['entities_id'] = $item->isEntityAssign() ? $item->getEntityID() : 0; - //update data - $container = new self(); - if ( - count($data) == 0 - || $container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction'])) - ) { - $item->input['date_mod'] = $_SESSION['glpi_currenttime']; - - return true; + if (array_key_exists('_plugin_fields_data_multi', $item->input)) { + $dataMulti = $item->input['_plugin_fields_data_multi']; + foreach ($dataMulti as $data) { + $data['entities_id'] = $item->isEntityAssign() ? $item->getEntityID() : 0; + //update data + $container = new self(); + if ( + count($data) == 0 + || $container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction'])) + ) { + $item->input['date_mod'] = $_SESSION['glpi_currenttime']; + continue; + } + continue; } - - return false; } - return true; } @@ -1672,69 +1741,62 @@ public static function preItemUpdate(CommonDBTM $item) */ public static function preItem(CommonDBTM $item) { - //find container (if not exist, do nothing) - if (isset($item->input['c_id'])) { - $c_id = $item->input['c_id']; - } elseif (isset($_REQUEST['c_id'])) { - $c_id = $_REQUEST['c_id']; - } else { - $type = 'dom'; - if (isset($_REQUEST['_plugin_fields_type'])) { - $type = $_REQUEST['_plugin_fields_type']; - } - $subtype = ''; - if ($type == 'domtab') { - $subtype = $_REQUEST['_plugin_fields_subtype']; - } - if (false === ($c_id = self::findContainer(get_Class($item), $type, $subtype))) { - // tries for 'tab' - if (false === ($c_id = self::findContainer(get_Class($item)))) { - return false; - } - } + $type = 'dom'; + if (isset($_REQUEST['_plugin_fields_type'])) { + $type = $_REQUEST['_plugin_fields_type']; + } + $subtype = ''; + if ($type == 'domtab') { + $subtype = $_REQUEST['_plugin_fields_subtype']; } - $loc_c = new PluginFieldsContainer(); - $loc_c->getFromDB($c_id); + $containers = self::findContainers($item->getType(), $type, $subtype, $item->getID()); - // check rights on $c_id + $all_data = []; - if (isset($_SESSION['glpiactiveprofile']['id']) && $_SESSION['glpiactiveprofile']['id'] != null && $c_id > 0) { - $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $c_id); - if (($right > READ) === false) { - return false; - } - } else { - return false; - } + foreach ($containers as $c_id) { + $loc_c = new PluginFieldsContainer(); + $loc_c->getFromDB($c_id); - // need to check if container is usable on this object entity - $entities = [$loc_c->fields['entities_id']]; - if ($loc_c->fields['is_recursive']) { - $entities = getSonsOf(getTableForItemType('Entity'), $loc_c->fields['entities_id']); - } + // check rights on $c_id - if (count($item->fields) === 0) { - $item->fields = $item->input; - } + if (isset($_SESSION['glpiactiveprofile']['id']) && $_SESSION['glpiactiveprofile']['id'] != null && $c_id > 0) { + $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $c_id); + if ($right > READ === false) { // Si le droit est insuffisant, on passe au container suivant + continue; + } + } else { + continue; + } - if ($item->isEntityAssign() && !in_array($item->getEntityID(), $entities)) { - return false; - } + // need to check if container is usable on this object entity + $entities = [$loc_c->fields['entities_id']]; + if ($loc_c->fields['is_recursive']) { + $entities = getSonsOf(getTableForItemType('Entity'), $loc_c->fields['entities_id']); + } - if (false !== ($data = self::populateData($c_id, $item))) { - if (self::validateValues($data, $item::getType(), isset($_REQUEST['massiveaction'])) === false) { - $item->input = []; + if (count($item->fields) === 0) { + $item->fields = $item->input; + } - return false; + if ($item->isEntityAssign() && !in_array($item->getEntityID(), $entities)) { + continue; } - $item->input['_plugin_fields_data'] = $data; - return true; + if (false !== ($data = self::populateData($c_id, $item))) { + if (self::validateValues($data, $item->getType(), isset($_REQUEST['massiveaction'])) === false) { + $item->input = []; + + return false; + } + $all_data[] = $data; + } } - return false; + $item->input['_plugin_fields_data_multi'] = $all_data; + + return true; } /** @@ -1745,7 +1807,7 @@ public static function preItem(CommonDBTM $item) * * @return array|false */ - private static function populateData($c_id, CommonDBTM $item) + public static function populateData($c_id, CommonDBTM $item) { //find fields associated to found container $field_obj = new PluginFieldsField(); @@ -1758,14 +1820,15 @@ private static function populateData($c_id, CommonDBTM $item) ); //prepare data to update - $data = ['plugin_fields_containers_id' => $c_id]; - if (!$item->isNewItem()) { - //no ID yet while creating - $data['items_id'] = $item->getID(); - } + $data = [ + 'plugin_fields_containers_id' => $c_id, + 'items_id' => $item->getID(), + 'itemtype' => $item->getType(), + 'entities_id' => $item->getEntityID(), + ]; // Add status so it can be used with status overrides - $status_field_name = PluginFieldsStatusOverride::getStatusFieldName($item->getType()); + $status_field_name = PluginFieldsStatusOverride::getStatusFieldName($item->getType()); $data[$status_field_name] = null; if (array_key_exists($status_field_name, $item->input) && $item->input[$status_field_name] !== '') { $data[$status_field_name] = (int) $item->input[$status_field_name]; @@ -1774,45 +1837,68 @@ private static function populateData($c_id, CommonDBTM $item) } $has_fields = false; + // Prefix for input names + $prefix = "plugin_fields_{$c_id}_"; + foreach ($fields as $field) { + $base_name = $field['name']; if ($field['type'] == 'glpi_item') { - $itemtype_key = sprintf('itemtype_%s', $field['name']); - $items_id_key = sprintf('items_id_%s', $field['name']); + $itemtype_key = "itemtype_{$base_name}"; + $items_id_key = "items_id_{$base_name}"; if (!isset($item->input[$itemtype_key], $item->input[$items_id_key])) { continue; // not a valid input } - $has_fields = true; - $data[$itemtype_key] = $item->input[$itemtype_key]; - $data[$items_id_key] = $item->input[$items_id_key]; + $has_fields = true; + $data[$itemtype_key] = $item->input[$itemtype_key]; + $data[$items_id_key] = $item->input[$items_id_key]; continue; // bypass unique field handling } - if (isset($item->input[$field['name']])) { - //standard field - $input = $field['name']; - } else { - //dropdown field - $input = 'plugin_fields_' . $field['name'] . 'dropdowns_id'; + // For other fields, the input name to be prefixed with "plugin_fields_{$c_id}_" and the field name + // "plugin_fields_{$c_id}_{$base_name}" + if ($field['type'] === 'dropdown') { + // For dropdown fields, the input name is "plugin_fields_{$c_id}_{$base_name}dropdowns_id" + $input = $prefix . $base_name . "dropdowns_id"; + if (isset($item->input[$input])) { + $has_fields = true; + $data[$base_name . "_dropdowns_id"] = $item->input[$input]; + } + // If the field is a dropdown with multiple selection, we need to check if the input name is defined + elseif ($field['multiple']) { + $multiple_key = $input; + $multiple_defined = '_' . $multiple_key . '_defined'; + if (isset($item->input[$multiple_key])) { + $has_fields = true; + $data[$base_name . "_dropdowns_id"] = $item->input[$multiple_key]; + } elseif (isset($item->input[$multiple_defined]) && $item->input[$multiple_defined]) { + $has_fields = true; + $data[$base_name . "_dropdowns_id"] = []; + } + } + continue; } + + // For fields standard, the input name is "plugin_fields_{$c_id}_{$base_name}" + $input = $prefix . $base_name; if (isset($item->input[$input])) { $has_fields = true; // Before is_number check, help user to have a number correct, during a massive action of a number field if ($field['type'] == 'number') { $item->input[$input] = str_replace(',', '.', $item->input[$input]); } - $data[$input] = $item->input[$input]; + $data[$base_name] = $item->input[$input]; if ($field['type'] === 'richtext') { - $filename_input = sprintf('_%s', $input); - $prefix_input = sprintf('_prefix_%s', $input); - $tag_input = sprintf('_tag_%s', $input); + $filename_input = "_" . $input; + $prefix_input = "_prefix_" . $input; + $tag_input = "_tag_" . $input; $data[$filename_input] = $item->input[$filename_input] ?? []; - $data[$prefix_input] = $item->input[$prefix_input] ?? []; - $data[$tag_input] = $item->input[$tag_input] ?? []; + $data[$prefix_input] = $item->input[$prefix_input] ?? []; + $data[$tag_input] = $item->input[$tag_input] ?? []; } } else { //the absence of the field in the input may be due to the fact that the input allows multiple selection @@ -1821,18 +1907,18 @@ private static function populateData($c_id, CommonDBTM $item) if ($field['multiple']) { //handle multi dropdown field if ($field['type'] == 'dropdown') { - $multiple_key = sprintf('plugin_fields_%sdropdowns_id', $field['name']); - $multiple_key_defined = '_' . $multiple_key . '_defined'; + $multiple_key = $prefix . $base_name . "dropdowns_id"; + $multiple_defined = '_' . $multiple_key . '_defined'; //values are defined by user if (isset($item->input[$multiple_key])) { - $data[$multiple_key] = $item->input[$multiple_key]; - $has_fields = true; + $data[$base_name . "_dropdowns_id"] = $item->input[$multiple_key]; + $has_fields = true; } elseif ( - isset($item->input[$multiple_key_defined]) - && $item->input[$multiple_key_defined] + isset($item->input[$multiple_defined]) + && $item->input[$multiple_defined] ) { //multi dropdown is empty or has been emptied - $data[$multiple_key] = []; - $has_fields = true; + $data[$base_name . "_dropdowns_id"] = []; + $has_fields = true; } } @@ -1840,10 +1926,10 @@ private static function populateData($c_id, CommonDBTM $item) if (preg_match('/^dropdown-(?.+)$/', $field['type'], $match) === 1) { //values are defined by user if (isset($item->input[$field['name']])) { - $data[$field['name']] = $item->input[$field['name']]; - $has_fields = true; + $data[$base_name] = $item->input[$field['name']]; + $has_fields = true; } else { //multi dropdown is empty or has been emptied - $data[$field['name']] = []; + $data[$base_name] = []; } } } diff --git a/inc/field.class.php b/inc/field.class.php index 02d43247..119eb3e3 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -871,8 +871,13 @@ public static function showDomContainer($id, $item, $type = 'dom', $subtype = '' $fields = []; } + $fieldTypeName = '_plugin_fields_type_' . $id; + $fieldSubTypeName = '_plugin_fields_subtype_' . $id; + echo Html::hidden('_plugin_fields_type', ['value' => $type]); echo Html::hidden('_plugin_fields_subtype', ['value' => $subtype]); + echo Html::hidden($fieldTypeName, ['value' => $type]); + echo Html::hidden($fieldSubTypeName, ['value' => $subtype]); echo self::prepareHtmlFields($fields, $item, true, true, false, $field_options); } @@ -904,172 +909,173 @@ public static function showForTab($params) $subtype = ''; } - //find container (if not exist, do nothing) - if (isset($_REQUEST['c_id'])) { - $c_id = $_REQUEST['c_id']; - } elseif (!$c_id = PluginFieldsContainer::findContainer(get_Class($item), $type, $subtype)) { - return; - } - - $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $c_id); - if ($right < READ) { + if (!isset($item->fields['id'])) { return; } + $itemId = $item->fields['id']; - Html::requireJs('tinymce'); + $container_ids = PluginFieldsContainer::findContainers(get_class($item), $type, $subtype, $itemId); - //need to check if container is usable on this object entity - $loc_c = new PluginFieldsContainer(); - $loc_c->getFromDB($c_id); - $entities = [$loc_c->fields['entities_id']]; - if ($loc_c->fields['is_recursive']) { - $entities = getSonsOf(getTableForItemType('Entity'), $loc_c->fields['entities_id']); - } + foreach ($container_ids as $container_id) { - if ($item->isEntityAssign()) { - $current_entity = $item->getEntityID(); - if (!in_array($current_entity, $entities)) { - return; + $right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $container_id); + if ($right < READ) { + continue; } - } - //parse REQUEST_URI - if (!isset($_SERVER['REQUEST_URI'])) { - return; - } - $current_url = $_SERVER['REQUEST_URI']; - if ( - strpos($current_url, '.form.php') === false - && strpos($current_url, '.injector.php') === false - && strpos($current_url, '.public.php') === false - && strpos($current_url, 'ajax/timeline.php') === false // ITILSolution load from timeline - ) { - return; - } + //need to check if container is usable on this object entity + $loc_c = new PluginFieldsContainer(); + $loc_c->getFromDB($container_id); + $entities = [$loc_c->fields['entities_id']]; + if ($loc_c->fields['is_recursive']) { + $entities = getSonsOf(getTableForItemType('Entity'), $loc_c->fields['entities_id']); + } - //Retrieve dom container - $itemtypes = PluginFieldsContainer::getUsedItemtypes($type, true); + if ($item->isEntityAssign()) { + $current_entity = $item->getEntityID(); + if (!in_array($current_entity, $entities)) { + continue; + } + } - //if no dom containers defined for this itemtype, do nothing (in_array case insensitive) - if (!in_array(strtolower($item::getType()), array_map('strtolower', $itemtypes))) { - return; - } + //parse REQUEST_URI + if (!isset($_SERVER['REQUEST_URI'])) { + continue; + } + $current_url = $_SERVER['REQUEST_URI']; + if ( + strpos($current_url, '.form.php') === false + && strpos($current_url, '.injector.php') === false + && strpos($current_url, '.public.php') === false + && strpos($current_url, 'ajax/timeline.php') === false // ITILSolution load from timeline + ) { + continue; + } - $html_id = 'plugin_fields_container_' . mt_rand(); - if (strpos($current_url, 'helpdesk.public.php') !== false) { - echo "
"; - echo "
"; - $field_options = [ - 'label_class' => 'col-lg-3', - 'input_class' => 'col-lg-9', - ]; - } else { - echo "
"; - } - $display_condition = new PluginFieldsContainerDisplayCondition(); - if ($display_condition->computeDisplayContainer($item, $c_id)) { - self::showDomContainer( - $c_id, - $item, - $type, - $subtype, - $field_options ?? [], - ); - } - if (strpos($current_url, 'helpdesk.public.php') !== false) { - echo '
'; - } - echo '
'; + //Retrieve dom container + $itemtypes = PluginFieldsContainer::getUsedItemtypes($type, true); - //JS to trigger any change and check if container need to be display or not - $ajax_url = Plugin::getWebDir('fields') . '/ajax/container.php'; - $items_id = !$item->isNewItem() ? $item->getID() : 0; - echo Html::scriptBlock( - <<"; + echo "
"; + $field_options = [ + 'label_class' => 'col-lg-3', + 'input_class' => 'col-lg-9', + ]; + } else { + echo "
"; + } + $display_condition = new PluginFieldsContainerDisplayCondition(); + if ($display_condition->computeDisplayContainer($item, $container_id)) { + self::showDomContainer( + $container_id, + $item, + $type, + $subtype, + $field_options ?? [], ); } - $( - function () { - const form = $('#{$html_id}').closest('form'); - form.on( - 'change', - 'input, select, textarea', - function(evt) { - if (evt.target.name == "itilcategories_id") { - // Do not refresh tab container when form is reloaded - // to prevent issues diues to duplicated calls - return; - } - if ($(evt.target).closest('#{$html_id}').length > 0) { - return; // Do nothing if element is inside fields container + if (strpos($current_url, 'helpdesk.public.php') !== false) { + echo '
'; + } + echo '
'; + + //JS to trigger any change and check if container need to be display or not + $ajax_url = Plugin::getWebDir('fields') . '/ajax/container.php'; + $items_id = !$item->isNewItem() ? $item->getID() : 0; + echo Html::scriptBlock( + << 0) { - return; // Do nothing if element is inside fields container - } - - if (refresh_timeout !== null) { - window.clearTimeout(refresh_timeout); - } - refresh_timeout = window.setTimeout(refreshContainer, 1000); - } - ); + $.ajax( + { + url: '{$ajax_url}', + type: 'GET', + data: { + action: 'get_fields_html', + id: {$container_id}, + itemtype: '{$item::getType()}', + items_id: {$items_id}, + type: '{$type}', + subtype: '{$subtype}', + input: data + }, + success: function(data) { + // Close open select2 dropdown that will be replaced + $('#{$html_id}').find('.select2-hidden-accessible').select2('close'); + // Refresh fields HTML + $('#{$html_id}').html(data); } } ); } + $( + function () { + const form = $('#{$html_id}').closest('form'); + form.on( + 'change', + 'input, select, textarea', + function(evt) { + if (evt.target.name == "itilcategories_id") { + // Do not refresh tab container when form is reloaded + // to prevent issues diues to duplicated calls + return; + } + if ($(evt.target).closest('#{$html_id}').length > 0) { + return; // Do nothing if element is inside fields container + } + refreshContainer(); + } + ); + + var refresh_timeout = null; + form.find('textarea').each( + function () { + const editor = tinymce.get(this.id); + if (editor !== null) { + editor.on( + 'change', + function(evt) { + if ($(evt.target.targetElm).closest('#{$html_id}').length > 0) { + return; // Do nothing if element is inside fields container + } + + if (refresh_timeout !== null) { + window.clearTimeout(refresh_timeout); + } + refresh_timeout = window.setTimeout(refreshContainer, 1000); + } + ); + } + } + ); + } + ); + JAVASCRIPT ); -JAVASCRIPT - ); + } } public static function prepareHtmlFields( diff --git a/inc/notificationtargetticket.class.php b/inc/notificationtargetticket.class.php new file mode 100644 index 00000000..ef7f1d0e --- /dev/null +++ b/inc/notificationtargetticket.class.php @@ -0,0 +1,47 @@ +raiseevent; + if (isset($target->obj->fields['id'])) { + $tickets_id = $target->obj->fields['id']; + + $containers = PluginFieldsContainer::findContainers('Ticket', 'dom', '', $tickets_id); + + foreach ($containers as $c_id) { + + $container_obj = new PluginFieldsContainer(); + $container_obj->getFromDB($c_id); + + if (empty($container_obj->fields)) { + continue; + } + + $container_name = $container_obj->fields['name']; + $bloc_classname = PluginFieldsContainer::getClassname('Ticket', $container_name); + + if (class_exists($bloc_classname)) { + + $bloc_obj = new $bloc_classname(); + + $values = $bloc_obj->find([ + 'plugin_fields_containers_id' => $c_id, + 'items_id' => $tickets_id, + ]); + $values = array_shift($values); + + foreach ($values as $field_name => $value) { + if (in_array($field_name, ['id', 'items_id', 'itemtype', 'plugin_fields_containers_id', 'entities_id'])) { + continue; + } + $key = "##fields.{$container_name}.{$field_name}##"; + $target->data[$key] = is_array($value) ? implode(', ', $value) : $value; + } + } + } + } + } +} diff --git a/setup.php b/setup.php index 3ba7b51c..2f21917b 100644 --- a/setup.php +++ b/setup.php @@ -190,6 +190,10 @@ function plugin_init_fields() 'PluginFieldsField', 'showForTab', ]; + + $PLUGIN_HOOKS['item_get_datas']['fields'] = [ + NotificationTargetTicket::class => [PluginFieldsNotificationTargetTicket::class, 'addNotificationDatas'], + ]; } } diff --git a/templates/fields.html.twig b/templates/fields.html.twig index b9480002..9e24a057 100644 --- a/templates/fields.html.twig +++ b/templates/fields.html.twig @@ -40,8 +40,9 @@ {% for field in fields %} + {% set cid = container.fields.id %} {% set type = field['type'] %} - {% set name = field['name'] %} + {% set name = 'plugin_fields_' ~ cid ~ '_' ~ field['name'] %} {% set label = field['label'] %} {% set value = item.input[name] ?: field['value'] %} {% set readonly = field['is_readonly'] %}