diff --git a/src/Forms/GridField/GridFieldDetailForm.php b/src/Forms/GridField/GridFieldDetailForm.php index e776f333daa..fcbb7043406 100644 --- a/src/Forms/GridField/GridFieldDetailForm.php +++ b/src/Forms/GridField/GridFieldDetailForm.php @@ -203,9 +203,7 @@ public function getLostRecordRedirection(GridField $gridField, HTTPRequest $requ } $existing = DataObject::get($list->dataClass())->byID($id); - if ($existing && $existing->hasMethod('CMSEditLink')) { - $link = $existing->CMSEditLink(); - } + $link = $existing?->CMSEditLink(); if ($link && $link == $request->getURL()) { throw new \LogicException(sprintf( diff --git a/src/ORM/CMSPreviewable.php b/src/ORM/CMSPreviewable.php index 8f5a6d82369..cba557662d2 100644 --- a/src/ORM/CMSPreviewable.php +++ b/src/ORM/CMSPreviewable.php @@ -32,9 +32,9 @@ public function PreviewLink($action = null); public function getMimeType(); /** - * @return string Link to the CMS-author view. Should point to a + * @return string|null Link to the CMS-author view. Should point to a * controller subclassing {@link LeftAndMain}. Example: * http://mysite.com/admin/edit/6 */ - public function CMSEditLink(); + public function CMSEditLink(): ?string; } diff --git a/src/ORM/DataObject.php b/src/ORM/DataObject.php index 3852d640c0c..c44b5153c1f 100644 --- a/src/ORM/DataObject.php +++ b/src/ORM/DataObject.php @@ -2692,6 +2692,16 @@ public function getViewerTemplates($suffix = '') return SSViewer::get_templates_by_class(static::class, $suffix, $this->baseClass()); } + /** + * Get the link for editing this record in the CMS. + */ + public function CMSEditLink(): ?string + { + $link = null; + $this->extend('updateCMSEditLink', $link); + return $link; + } + /** * Gets the value of a field. * Called by {@link __get()} and any getFieldName() methods you might create. @@ -4143,6 +4153,7 @@ public static function enable_subclass_access() */ private static $casting = [ "Title" => 'Text', + 'CMSEditLink' => 'Text', ]; /**