ENH PHP 8.1 compatibility

This commit is contained in:
Steve Boyd 2022-04-13 13:54:56 +12:00
parent 5aca443a7c
commit 51d29b3d5a
3 changed files with 11 additions and 11 deletions

View File

@ -66,7 +66,7 @@ class WidgetAreaEditor extends FormField
$available = Config::inst()->get($class, 'only_available_in');
if (!empty($available) && is_array($available)) {
if (in_array($this->Name, $available)) {
if (in_array($this->Name, $available ?? [])) {
$widgets->push(singleton($class));
}
} else {
@ -168,12 +168,12 @@ class WidgetAreaEditor extends FormField
if (empty($newWidgetData['Type'])) {
$newWidgetData['Type'] = '';
}
$newWidgetData['Type'] = str_replace('_', '\\', $newWidgetData['Type']);
$newWidgetData['Type'] = str_replace('_', '\\', $newWidgetData['Type'] ?? '');
// create a new object
if (!$widget
&& !empty($newWidgetData['Type'])
&& class_exists($newWidgetData['Type'])
&& class_exists($newWidgetData['Type'] ?? '')
&& is_subclass_of($newWidgetData['Type'], Widget::class)
) {
$widget = Injector::inst()->create($newWidgetData['Type']);

View File

@ -191,7 +191,7 @@ class Widget extends DataObject
if ($value) {
$field->setValue($value);
}
$namefiltered = preg_replace("/([A-Za-z0-9\-_]+)/", "Widget[" . $this->FormID . "][\\1]", $name);
$namefiltered = preg_replace("/([A-Za-z0-9\-_]+)/", "Widget[" . $this->FormID . "][\\1]", $name ?? '');
$field->setName($namefiltered);
$outputFields->push($field);
@ -230,14 +230,14 @@ class Widget extends DataObject
return $this->controller;
}
foreach (array_reverse(ClassInfo::ancestry(get_class($this))) as $widgetClass) {
foreach (array_reverse(ClassInfo::ancestry(get_class($this)) ?? []) as $widgetClass) {
$controllerClass = "{$widgetClass}Controller";
if (class_exists($controllerClass)) {
if (class_exists($controllerClass ?? '')) {
break;
}
}
if (!class_exists($controllerClass)) {
if (!class_exists($controllerClass ?? '')) {
throw new Exception('Could not find controller class for ' . static::class);
}
@ -268,7 +268,7 @@ class Widget extends DataObject
//Look for checkbox fields not present in the data
foreach ($fields as $field) {
if ($field instanceof CheckboxField && !array_key_exists($field->getName(), $data)) {
if ($field instanceof CheckboxField && !array_key_exists($field->getName(), $data ?? [])) {
$field->setValue(false);
$field->saveInto($this);
}

View File

@ -106,7 +106,7 @@ class WidgetController extends Controller
*/
public function Content()
{
return $this->renderWith(array_reverse(ClassInfo::ancestry(get_class($this->widget))));
return $this->renderWith(array_reverse(ClassInfo::ancestry(get_class($this->widget)) ?? []));
}
/**
@ -136,8 +136,8 @@ class WidgetController extends Controller
$leftandmain->doInit();
// Decode if fully qualified - @see Widget::ClassName
$className = str_replace('_', '\\', $this->urlParams['ID']);
if (class_exists($className) && is_subclass_of($className, Widget::class)) {
$className = str_replace('_', '\\', $this->urlParams['ID'] ?? '');
if (class_exists($className ?? '') && is_subclass_of($className, Widget::class)) {
$obj = new $className();
return $obj->EditableSegment();
} else {