Performance improvements for customfields where we have just 1 field, not the whole list

This commit is contained in:
nathan 2024-04-29 13:57:06 -06:00 committed by ralf
parent 417af60ba3
commit 559d8fba63
2 changed files with 14 additions and 13 deletions

View File

@ -368,10 +368,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]};
}
}
}

View File

@ -170,6 +170,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
@ -192,16 +203,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)