Merge pull request #209 from creative-commoners/pulls/2/php81

ENH PHP 8.1 compatibility
This commit is contained in:
Guy Sartorelli 2022-04-26 17:57:37 +12:00 committed by GitHub
commit d486842a69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -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());
}
/**

View File

@ -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 ?? []);
}
/**

View File

@ -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);