Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW Provide a standardised CMSEditLink method #11338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Forms/GridField/GridFieldDetailForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected function getRecordFromRequest(GridField $gridField, HTTPRequest $reque

/**
* Try and find another URL at which the given record can be edited.
* If redirectMissingRecords is true and the record has a CMSEditLink method, that value will be returned.
* If redirectMissingRecords is true and the record has a getCMSEditLink method, that value will be returned.
* This only works when the list passed to the GridField is a {@link DataList}.
*
* @param $gridField The current GridField
Expand Down 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?->getCMSEditLink();

if ($link && $link == $request->getURL()) {
throw new \LogicException(sprintf(
Expand Down Expand Up @@ -282,7 +280,7 @@ public function getName()
* Enable redirection to missing records.
*
* If a GridField shows a filtered list, and the record is not in the list but exists in the
* database, and the record has a CMSEditLink method, then the system will redirect to the
* database, and the record has a getCMSEditLink method, then the system will redirect to the
* URL returned by that method.
*/
public function setRedirectMissingRecords(bool $redirectMissingRecords): GridFieldDetailForm
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 getCMSEditLink(): ?string;
}
20 changes: 20 additions & 0 deletions src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2692,6 +2692,25 @@ 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 getCMSEditLink(): ?string
{
$link = null;
$this->extend('updateCMSEditLink', $link);
return $link;
}

/**
* @deprecated 6.0.0 Use getCMSEditLink() instead
*/
public function CMSEditLink()
{
Deprecation::notice('6.0.0', 'Use getCMSEditLink() instead');
return $this->getCMSEditLink();
}

/**
* Gets the value of a field.
* Called by {@link __get()} and any getFieldName() methods you might create.
Expand Down Expand Up @@ -4143,6 +4162,7 @@ public static function enable_subclass_access()
*/
private static $casting = [
"Title" => 'Text',
'CMSEditLink' => 'Text',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

];

/**
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 getCMSEditLink(): ?string
{
return sprintf('my-admin/%d', $this->ID);
}
Expand Down
Loading