Skip to content

Commit

Permalink
ENH PHP 8.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Apr 13, 2022
1 parent 87ccfba commit 16aece8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/Forms/GridFieldSiteTreeAddNewButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public function getAllowedChildren(SiteTree $parent = null)
// Note: Second argument to SiteTree::canCreate will support inherited permissions
// post 3.1.12, and will default to the old permission model in 3.1.11 or below
// See http://docs.silverstripe.org/en/changelogs/3.1.11
if ($instance->canCreate(null, array('Parent' => $parent)) && in_array($class, $nonHiddenPageTypes)) {
if (
$instance->canCreate(null, array('Parent' => $parent)) &&
in_array($class, $nonHiddenPageTypes ?? [])
) {
$children[$class] = $instance->i18n_singular_name();
}
}
Expand All @@ -72,7 +75,7 @@ public function getHTMLFragments($gridField)
$children = $this->getAllowedChildren($parent);
if (empty($children)) {
return array();
} elseif (count($children) > 1) {
} elseif (count($children ?? []) > 1) {
$pageTypes = DropdownField::create('PageType', 'Page Type', $children, $parent->defaultChild());
$pageTypes
->setFieldHolderTemplate(__CLASS__ . '_holder')
Expand All @@ -88,7 +91,7 @@ public function getHTMLFragments($gridField)
);
}
} else {
$keys = array_keys($children);
$keys = array_keys($children ?? []);
$pageTypes = HiddenField::create('PageType', 'Page Type', $keys[0]);

$state->pageType = $keys[0];
Expand Down Expand Up @@ -140,7 +143,7 @@ public function getActions($gridField)
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName == 'add') {
$tmpData = json_decode($data['ChildPages']['GridState'], true);
$tmpData = json_decode($data['ChildPages']['GridState'] ?? '', true);
/** @skipUpgrade */
$tmpData = $tmpData['GridFieldSiteTreeAddNewButton'];

Expand Down
2 changes: 1 addition & 1 deletion src/Forms/GridFieldSiteTreeState.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class GridFieldSiteTreeState implements GridField_ColumnProvider
public function augmentColumns($gridField, &$columns)
{
// Ensure Actions always appears as the last column.
$key = array_search('Actions', $columns);
$key = array_search('Actions', $columns ?? []);
if ($key !== false) {
unset($columns[$key]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Lumberjack.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function stageChildren($showAll = false)
protected function excludeSiteTreeClassNames($list)
{
$classNames = $this->owner->getExcludedSiteTreeClassNames();
if ($this->shouldFilter() && count($classNames)) {
if ($this->shouldFilter() && count($classNames ?? [])) {
// Filter the SiteTree
$list = $list->exclude('ClassName', $classNames);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/LumberjackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public function testGetExcludedSiteTreeClassNames()
*/
protected function filteredClassNames($classNames, $explicitClassNames)
{
$classNames = array_filter($classNames, function ($value) use ($explicitClassNames) {
return in_array($value, $explicitClassNames);
$classNames = array_filter($classNames ?? [], function ($value) use ($explicitClassNames) {
return in_array($value, $explicitClassNames ?? []);
});
return $classNames;
}
Expand Down

0 comments on commit 16aece8

Please sign in to comment.