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
parent c63f465eb8
commit d60d667bd3
2 changed files with 14 additions and 13 deletions

View File

@ -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]};
}
}
}

View File

@ -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)