Once again fix saving string value to '' so that we can empty LabelFormat

pull/3204/head
Isaac Connor 2021-03-30 13:31:26 -04:00
parent beb7a75d5a
commit 8582c1a652
1 changed files with 20 additions and 15 deletions

View File

@ -187,7 +187,8 @@ class ZM_Object {
# perhaps should turn into a comma-separated string
$this->{$field} = implode(',', $value);
} else if (is_string($value)) {
if ( array_key_exists($field, $this->defaults) && is_array($this->defaults[$field]) && isset($this->defaults[$field]['filter_regexp']) ) {
if (array_key_exists($field, $this->defaults)) {
if (is_array($this->defaults[$field]) && isset($this->defaults[$field]['filter_regexp'])) {
if (is_array($this->defaults[$field]['filter_regexp'])) {
foreach ($this->defaults[$field]['filter_regexp'] as $regexp) {
$this->{$field} = preg_replace($regexp, '', trim($value));
@ -195,12 +196,16 @@ class ZM_Object {
} else {
$this->{$field} = preg_replace($this->defaults[$field]['filter_regexp'], '', trim($value));
}
} else if ( $value == '' and array_key_exists($field, $this->defaults) ) {
} else if ($value == '') {
if (is_array($this->defaults[$field])) {
$this->{$field} = $this->defaults[$field]['default'];
} else if (is_string($this->defaults[$field])) {
# if the default is a string, don't set it. Having a default for empty string is to set null for numbers.
$this->{$field} = $value;
} else {
$this->{$field} = $this->defaults[$field];
}
} # need a default
} else {
$this->{$field} = $value;
}