Skip to content

Commit

Permalink
FIX undefined index error in CMS
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NightJar committed Mar 28, 2023
1 parent 9907209 commit e200364
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,13 +739,15 @@ public function getAbsoluteLiveLink($includeStageEqualsLive = true)
/**
* 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] ?? '';
}

/**
Expand Down

0 comments on commit e200364

Please sign in to comment.