From 824b5e0b678669ca4144304d329e1cf9484175b5 Mon Sep 17 00:00:00 2001 From: Tom Yrjas Date: Mon, 29 Jun 2020 14:12:01 +0300 Subject: [PATCH 1/2] BUGFIX: Ensure $items isn't null in GridFieldDetailForm_ItemRequest->Breadcrumbs() prior to performing operations on it. --- .../GridFieldDetailForm_ItemRequest.php | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php b/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php index 9aab66baf..2a0a0a7ea 100644 --- a/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php +++ b/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php @@ -786,17 +786,19 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler /** @var ArrayList $items */ $items = $this->popupController->Breadcrumbs($unlinked); - if ($this->record && $this->record->ID) { - $title = ($this->record->Title) ? $this->record->Title : "#{$this->record->ID}"; - $items->push(new ArrayData([ - 'Title' => $title, - 'Link' => $this->Link() - ])); - } else { - $items->push(new ArrayData([ - 'Title' => _t('SilverStripe\\Forms\\GridField\\GridField.NewRecord', 'New {type}', ['type' => $this->record->i18n_singular_name()]), - 'Link' => false - ])); + if ($items) { + if ($this->record && $this->record->ID) { + $title = ($this->record->Title) ? $this->record->Title : "#{$this->record->ID}"; + $items->push(new ArrayData([ + 'Title' => $title, + 'Link' => $this->Link() + ])); + } else { + $items->push(new ArrayData([ + 'Title' => _t('SilverStripe\\Forms\\GridField\\GridField.NewRecord', 'New {type}', ['type' => $this->record->i18n_singular_name()]), + 'Link' => false + ])); + } } $this->extend('updateBreadcrumbs', $items); From 00ee8d8abf4ca0535eee55bb722ccc9ea41e9fec Mon Sep 17 00:00:00 2001 From: Tom Yrjas Date: Mon, 29 Jun 2020 16:07:24 +0300 Subject: [PATCH 2/2] BUGFIX: Re-declare $items to be an ArrayList if it's null getBackLink() modified to tolerate empty ArrayList --- .../GridFieldDetailForm_ItemRequest.php | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php b/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php index 2a0a0a7ea..9db76aac0 100644 --- a/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php +++ b/src/Forms/GridField/GridFieldDetailForm_ItemRequest.php @@ -464,8 +464,10 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler if ($toplevelController->hasMethod('Backlink')) { $backlink = $toplevelController->Backlink(); } elseif ($this->popupController->hasMethod('Breadcrumbs')) { - $parents = $this->popupController->Breadcrumbs(false)->items; - $backlink = array_pop($parents)->Link; + $parents = $this->popupController->Breadcrumbs(false); + if ($parents && $parents = $parents->items) { + $backlink = array_pop($parents)->Link; + } } } if (!$backlink) { @@ -786,19 +788,21 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler /** @var ArrayList $items */ $items = $this->popupController->Breadcrumbs($unlinked); - if ($items) { - if ($this->record && $this->record->ID) { - $title = ($this->record->Title) ? $this->record->Title : "#{$this->record->ID}"; - $items->push(new ArrayData([ - 'Title' => $title, - 'Link' => $this->Link() - ])); - } else { - $items->push(new ArrayData([ - 'Title' => _t('SilverStripe\\Forms\\GridField\\GridField.NewRecord', 'New {type}', ['type' => $this->record->i18n_singular_name()]), - 'Link' => false - ])); - } + if (!$items) { + $items = new ArrayList(); + } + + if ($this->record && $this->record->ID) { + $title = ($this->record->Title) ? $this->record->Title : "#{$this->record->ID}"; + $items->push(new ArrayData([ + 'Title' => $title, + 'Link' => $this->Link() + ])); + } else { + $items->push(new ArrayData([ + 'Title' => _t('SilverStripe\\Forms\\GridField\\GridField.NewRecord', 'New {type}', ['type' => $this->record->i18n_singular_name()]), + 'Link' => false + ])); } $this->extend('updateBreadcrumbs', $items);