Skip to content

Commit

Permalink
API Change public CMSEditLink to protected updateCMSEditLink
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Aug 19, 2024
1 parent f43bbce commit a9faef1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
15 changes: 11 additions & 4 deletions code/CMSEditLinkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,21 @@ public function getCMSEditLinkForManagedDataObject(DataObject $obj, string $reci
}

/**
* Get a link to edit this DataObject in the CMS.
* Provide a link to edit this DataObject in the CMS if there isn't one already.
* @throws LogicException if a link cannot be established
* e.g. if the object is not in a has_many relation or not edited inside a GridField.
*/
public function CMSEditLink(): string
protected function updateCMSEditLink(?string &$link): void
{
// Don't update the link if it has already been established.
if ($link) {
return;
}

/** @var DataObject|LeftAndMain|null $owner */
$owner = $this->owner->getCMSEditOwner();
if (!$owner || !$owner->exists()) {
return '';
return;
}

if (!$owner->hasMethod('getCMSEditLinkForManagedDataObject')) {
Expand All @@ -89,7 +96,7 @@ public function CMSEditLink(): string
} else {
$relativeLink = $owner->getCMSEditLinkForManagedDataObject($this->owner);
}
return Director::absoluteURL((string) $relativeLink);
$link = Director::absoluteURL($relativeLink);
}

private function getCMSEditLinkForRelation(array $componentConfig, DataObject $obj, string $reciprocalRelation, FieldList $fields): string
Expand Down
4 changes: 2 additions & 2 deletions code/Forms/UsedOnTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function usage(HTTPRequest $request)
'id' => $dataObject->ID,
'title' => $dataObject->getTitle() ?: _t(__CLASS__ . '.UNTITLED', 'Untitled'),
'type' => ucfirst($dataObject->i18n_singular_name() ?? ''),
'link' => $dataObject->hasMethod('CMSEditLink') ? $dataObject->CMSEditLink() : null,
'link' => $dataObject->CMSEditLink(),
'ancestors' => []
];

Expand All @@ -115,7 +115,7 @@ public function usage(HTTPRequest $request)
foreach ($ancestorDataObjects as $ancestorDataObject) {
$tableRowData['ancestors'][] = [
'title' => $ancestorDataObject->getTitle() ?: _t(__CLASS__ . '.UNTITLED', 'Untitled'),
'link' => $ancestorDataObject->hasMethod('CMSEditLink') ? $ancestorDataObject->CMSEditLink() : null,
'link' => $ancestorDataObject->CMSEditLink(),
];
}
$usageData[] = $tableRowData;
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Navigator/UnversionedRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getMimeType()
return 'text/html';
}

public function CMSEditLink()
public function CMSEditLink(): ?string
{
return null;
}
Expand Down

0 comments on commit a9faef1

Please sign in to comment.