mirror of
https://github.com/silverstripe/silverstripe-tagfield
synced 2024-06-17 10:11:35 +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)
|
public function setValue($value, $source = null)
|
||||||
{
|
{
|
||||||
if (is_string($value)) {
|
if (is_string($value)) {
|
||||||
$value = explode(',', $value);
|
$value = explode(',', $value ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($source instanceof DataObject) {
|
if ($source instanceof DataObject) {
|
||||||
$name = $this->getName();
|
$name = $this->getName();
|
||||||
$value = explode(',', $source->$name);
|
$value = explode(',', $source->$name ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($source instanceof SS_List) {
|
if ($source instanceof SS_List) {
|
||||||
|
@ -270,7 +270,7 @@ class StringTagField extends DropdownField
|
||||||
$value = [];
|
$value = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::setValue(array_filter($value));
|
return parent::setValue(array_filter($value ?? []));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveInto(DataObjectInterface $record)
|
public function saveInto(DataObjectInterface $record)
|
||||||
|
@ -328,7 +328,7 @@ class StringTagField extends DropdownField
|
||||||
/** @var ArrayData $tag */
|
/** @var ArrayData $tag */
|
||||||
$tagValue = $tag->Value;
|
$tagValue = $tag->Value;
|
||||||
// Map into a distinct list (prevent duplicates)
|
// 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] = [
|
$items[$tagValue] = [
|
||||||
'id' => $tag->Title,
|
'id' => $tag->Title,
|
||||||
'text' => $tag->Value,
|
'text' => $tag->Value,
|
||||||
|
@ -336,7 +336,7 @@ class StringTagField extends DropdownField
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// @todo do we actually need lazy loading limits for StringTagField?
|
// @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()) {
|
if (!$this->getShouldLazyLoad()) {
|
||||||
$schema['options'] = array_values($this->getOptions()->toNestedArray());
|
$schema['options'] = array_values($this->getOptions()->toNestedArray() ?? []);
|
||||||
} else {
|
} else {
|
||||||
$schema['optionUrl'] = $this->getSuggestURL();
|
$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)
|
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($expected);
|
||||||
sort($actual);
|
sort($actual);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user