mirror of
https://github.com/silverstripe/silverstripe-tagfield
synced 2024-10-22 11:05:32 +02:00
Merge pull request #209 from creative-commoners/pulls/2/php81
ENH PHP 8.1 compatibility
This commit is contained in:
commit
d486842a69
@ -254,12 +254,12 @@ class StringTagField extends DropdownField
|
||||
public function setValue($value, $source = null)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$value = explode(',', $value);
|
||||
$value = explode(',', $value ?? '');
|
||||
}
|
||||
|
||||
if ($source instanceof DataObject) {
|
||||
$name = $this->getName();
|
||||
$value = explode(',', $source->$name);
|
||||
$value = explode(',', $source->$name ?? '');
|
||||
}
|
||||
|
||||
if ($source instanceof SS_List) {
|
||||
@ -270,7 +270,7 @@ class StringTagField extends DropdownField
|
||||
$value = [];
|
||||
}
|
||||
|
||||
return parent::setValue(array_filter($value));
|
||||
return parent::setValue(array_filter($value ?? []));
|
||||
}
|
||||
|
||||
public function saveInto(DataObjectInterface $record)
|
||||
@ -328,7 +328,7 @@ class StringTagField extends DropdownField
|
||||
/** @var ArrayData $tag */
|
||||
$tagValue = $tag->Value;
|
||||
// Map into a distinct list (prevent duplicates)
|
||||
if (stripos($tagValue, $term) !== false && !array_key_exists($tagValue, $items)) {
|
||||
if (stripos($tagValue ?? '', $term ?? '') !== false && !array_key_exists($tagValue, $items ?? [])) {
|
||||
$items[$tagValue] = [
|
||||
'id' => $tag->Title,
|
||||
'text' => $tag->Value,
|
||||
@ -336,7 +336,7 @@ class StringTagField extends DropdownField
|
||||
}
|
||||
}
|
||||
// @todo do we actually need lazy loading limits for StringTagField?
|
||||
return array_slice(array_values($items), 0, $this->getLazyLoadItemLimit());
|
||||
return array_slice(array_values($items ?? []), 0, $this->getLazyLoadItemLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,7 +234,7 @@ class TagField extends MultiSelectField
|
||||
);
|
||||
|
||||
if (!$this->getShouldLazyLoad()) {
|
||||
$schema['options'] = array_values($this->getOptions()->toNestedArray());
|
||||
$schema['options'] = array_values($this->getOptions()->toNestedArray() ?? []);
|
||||
} else {
|
||||
$schema['optionUrl'] = $this->getSuggestURL();
|
||||
}
|
||||
@ -421,7 +421,7 @@ class TagField extends MultiSelectField
|
||||
}
|
||||
}
|
||||
|
||||
$relation->setByIDList(array_filter($ids));
|
||||
$relation->setByIDList(array_filter($ids ?? []));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -513,7 +513,7 @@ class TagField extends MultiSelectField
|
||||
];
|
||||
}
|
||||
|
||||
return array_values($items);
|
||||
return array_values($items ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +72,7 @@ class TagFieldTest extends SapphireTest
|
||||
*/
|
||||
protected function compareTagLists(array $expected, DataList $actualSource)
|
||||
{
|
||||
$actual = array_values($actualSource->map('ID', 'Title')->toArray());
|
||||
$actual = array_values($actualSource->map('ID', 'Title')->toArray() ?? []);
|
||||
sort($expected);
|
||||
sort($actual);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user