From e20036482b4c3e620d91018551b4745db14f2334 Mon Sep 17 00:00:00 2001 From: Dylan Wagstaff Date: Tue, 28 Mar 2023 16:34:11 +1300 Subject: [PATCH] FIX undefined index error in CMS With the CMS 4.12 update functionality was altered to utilise an Extension to obtain the CMS Edit link for a page, rather than having SiteTree do it internally. Unfortunately the default return case for `extend` (see Extensible) is an _empty_ array. This leave code potentially referencing an array offset that doesn't exist ([0]). PHP 8 is less forgiving that it's predecessors on this kind of behaviour. We should check that the responses from extensions exist before trying to reference them. --- code/Model/SiteTree.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index 5899d5a9..feaa82c1 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -739,13 +739,15 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi /** * Generates a link to edit this page in the CMS. * + * Implemented here to satisfy the CMSPreviewable interface, but data is intended to be loaded via Extension + * + * @see SilverStripe\Admin\CMSEditLinkExtension + * * @return string */ public function CMSEditLink() { - // This method has to be implemented here to satisfy the CMSPreviewable interface. - // See the actual implementation in CMSEditLinkExtension. - return $this->extend('CMSEditLink')[0]; + return $this->extend('CMSEditLink')[0] ?? ''; } /**