Skip to content

Commit

Permalink
NEW Provide a standardised CMSEditLink method
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Aug 19, 2024
1 parent 64a17e0 commit 147fa90
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/Forms/GridField/GridFieldDetailForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/CMSPreviewable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
11 changes: 11 additions & 0 deletions src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -4143,6 +4153,7 @@ public static function enable_subclass_access()
*/
private static $casting = [
"Title" => 'Text',
'CMSEditLink' => 'Text',
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getCMSValidator()
);
}

public function CMSEditLink()
public function CMSEditLink(): ?string
{
return sprintf('my-admin/%d', $this->ID);
}
Expand Down

0 comments on commit 147fa90

Please sign in to comment.