diff --git a/src/Fields/KeyValueField.php b/src/Fields/KeyValueField.php index d8a59e6..893037b 100755 --- a/src/Fields/KeyValueField.php +++ b/src/Fields/KeyValueField.php @@ -148,7 +148,7 @@ protected function createSelectList($number, $name, $values, $selected = '', $pl $options .= HTML::createTag('option', $attrs, Convert::raw2xml($title)); } - if (count($values)) { + if (count($values ?? [])) { $attrs = [ 'class' => 'text mventryfield mvdropdown '.($this->extraClass() ? $this->extraClass() : ''), 'id' => $this->id().MultiValueTextField::KEY_SEP.$number, @@ -189,7 +189,7 @@ public function setValue($v, $data = null) $newVal = []; for ($i = 0, $c = count($v['key']); $i < $c; $i++) { - if (strlen($v['key'][$i]) && strlen($v['val'][$i])) { + if (strlen($v['key'][$i] ?? '') && strlen($v['val'][$i] ?? '')) { $newVal[$v['key'][$i]] = $v['val'][$i]; } } diff --git a/src/Fields/MultiValueCheckboxField.php b/src/Fields/MultiValueCheckboxField.php index f28e32f..ebe56fd 100755 --- a/src/Fields/MultiValueCheckboxField.php +++ b/src/Fields/MultiValueCheckboxField.php @@ -49,7 +49,7 @@ public function Field($properties = []) if ($this->storeKeys && is_array($values)) { // use the keys instead, as that's how we've stored things - $values = array_keys($values); + $values = array_keys($values ?? []); } } @@ -77,8 +77,8 @@ public function Field($properties = []) } } } elseif ($values && is_string($values)) { - $items = explode(',', $values); - $items = str_replace('{comma}', ',', $items); + $items = explode(',', $values ?? ''); + $items = str_replace('{comma}', ',', $items ?? ''); } } } else { @@ -86,8 +86,8 @@ public function Field($properties = []) if (is_a($values, 'DataObjectSet') || is_array($values)) { $items = $values; } else { - $items = explode(',', $values); - $items = str_replace('{comma}', ',', $items); + $items = explode(',', $values ?? ''); + $items = str_replace('{comma}', ',', $items ?? ''); } } @@ -117,15 +117,15 @@ public function Field($properties = []) $odd = ($odd + 1) % 2; $extraClass = $odd ? 'odd' : 'even'; - $extraClass .= ' val'.str_replace(' ', '', $key); - $itemID = $this->id().'_'.preg_replace('/[^a-zA-Z0-9]+/', '', $key); + $extraClass .= ' val'.str_replace(' ', '', $key ?? ''); + $itemID = $this->id().'_'.preg_replace('/[^a-zA-Z0-9]+/', '', $key ?? ''); $checked = ''; if (isset($items)) { - $checked = (in_array($key, $items) || in_array($key, $this->defaultItems)) + $checked = (in_array($key, $items ?? []) || in_array($key, $this->defaultItems ?? [])) ? ' checked="checked"' : ''; } - $disabled = ($this->disabled || in_array($key, $this->disabledItems)) + $disabled = ($this->disabled || in_array($key, $this->disabledItems ?? [])) ? $disabled = ' disabled="disabled"' : ''; $options .= "