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 .= "
  • name[$key]\"" @@ -220,7 +220,7 @@ public function dataValue() $filtered = []; foreach ($this->value as $item) { if ($item) { - $filtered[] = str_replace(",", "{comma}", $item); + $filtered[] = str_replace(",", "{comma}", $item ?? ''); } } @@ -271,7 +271,7 @@ public function performReadonlyTransformation() // Items is an array or single piece of string (including comma seperated string) } else { if (!is_array($items)) { - $items = preg_split('/ *, */', trim($items)); + $items = preg_split('/ *, */', trim($items ?? '')); } foreach ($items as $item) { diff --git a/src/Fields/MultiValueListField.php b/src/Fields/MultiValueListField.php index 24690b7..838b9e2 100755 --- a/src/Fields/MultiValueListField.php +++ b/src/Fields/MultiValueListField.php @@ -42,7 +42,7 @@ public function Field($properties = []) foreach ($this->source as $index => $title) { $attrs = ['value' => $index]; - if (in_array($index, $this->value)) { + if (in_array($index, $this->value ?? [])) { $attrs['selected'] = 'selected'; } $options .= HTML::createTag('option', $attrs, Convert::raw2xml($title)); diff --git a/src/Fields/MultiValueTextField.php b/src/Fields/MultiValueTextField.php index 6db95ba..02fdad3 100755 --- a/src/Fields/MultiValueTextField.php +++ b/src/Fields/MultiValueTextField.php @@ -62,11 +62,11 @@ public function Field($properties = []) // add an empty row if (!$this->readonly) { // assume next pos equals to the number of existing fields which gives index+1 in a zero-indexed list - $attributes['id'] = $this->id().MultiValueTextField::KEY_SEP.count($fields); + $attributes['id'] = $this->id().MultiValueTextField::KEY_SEP.count($fields ?? []); $fields[] = $this->createInput($attributes); } - if (count($fields)) { + if (count($fields ?? [])) { return '