From d60d667bd3ea501b9fc772df55364e7006fe4093 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 29 Apr 2024 13:57:06 -0600 Subject: [PATCH] Performance improvements for customfields where we have just 1 field, not the whole list --- .../etemplate/et2_extension_customfields.ts | 6 +++--- api/src/Etemplate/Widget/Customfields.php | 21 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/api/js/etemplate/et2_extension_customfields.ts b/api/js/etemplate/et2_extension_customfields.ts index 4bae9442f8..5d070838bd 100644 --- a/api/js/etemplate/et2_extension_customfields.ts +++ b/api/js/etemplate/et2_extension_customfields.ts @@ -453,10 +453,10 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac { for(let key in data) { - // Don't overwrite fields with global values - if(global_data[key] && key !== 'fields') + // Don't overwrite fields / customfields with global values + if(global_data[key] && key !== 'fields' && !(key == "customfields" && typeof data.customfields != undefined)) { - data[key] = jQuery.extend(true, {}, data[key], global_data[key]); + data[key] = {...data[key], ...global_data[key]}; } } } diff --git a/api/src/Etemplate/Widget/Customfields.php b/api/src/Etemplate/Widget/Customfields.php index 4d26803c12..1c4916a352 100644 --- a/api/src/Etemplate/Widget/Customfields.php +++ b/api/src/Etemplate/Widget/Customfields.php @@ -171,6 +171,17 @@ class Customfields extends Transformer $use_private = self::expand_name($this->attrs['private'] ?? null,0,0,'','',self::$cont); $this->attrs['type_filter'] = self::expand_name($this->attrs['type_filter'] ?? null,0,0,'','',self::$cont); + // check if name refers to a single custom field --> show only that + $matches = null; + if(($pos = strpos($form_name, $this->attrs['prefix'])) !== false && // allow the prefixed name to be an array index too + preg_match($preg = '/' . $this->attrs['prefix'] . '([^\]]+)/', $form_name, $matches) && isset($fields[$name = $matches[1]])) + { + $fields = array($name => $fields[$name]); + $value = self::get_array(self::$request->content, $form_name, false, true); + $fields[$name]['value'] = $value; + $form_name = $this->attrs['prefix'] . $name; + } + foreach((array)$fields as $key => $field) { // remove private or non-private cf's, if only one kind should be displayed @@ -193,16 +204,6 @@ class Customfields extends Transformer unset($fields[$key]); } } - // check if name refers to a single custom field --> show only that - $matches = null; - if (($pos=strpos($form_name,$this->attrs['prefix'])) !== false && // allow the prefixed name to be an array index too - preg_match($preg = '/'.$this->attrs['prefix'].'([^\]]+)/',$form_name,$matches) && isset($fields[$name=$matches[1]])) - { - $fields = array($name => $fields[$name]); - $value = self::get_array(self::$request->content, $form_name, false, true); - $fields[$name]['value'] = $value; - $form_name = $this->attrs['prefix'] . $name; - } if(!is_array($fields)) $fields = array(); switch($type = $this->type)