diff --git a/docs/en/05_examples/00_elementalarea_with_dataobject.md b/docs/en/05_examples/00_elementalarea_with_dataobject.md index 19ef0d06..d35fa707 100644 --- a/docs/en/05_examples/00_elementalarea_with_dataobject.md +++ b/docs/en/05_examples/00_elementalarea_with_dataobject.md @@ -55,8 +55,8 @@ class BlogPost extends DataObject } ``` -If you are using `ElementalArea` together with `DataObject`, it is important to define the `CMSEditLink()` method in the class. -[`BaseElement::CMSEditLink()`](api:DNADesign\Elemental\Models\BaseElement::CMSEditLink()) relies on a valid CMS link being available in the parent `DataObject` - in this case, `BlogPost`. It is used to navigate directly to the editing section of the particular element. +If you are using `ElementalArea` together with `DataObject`, it is important to define the `getCMSEditLink()` method in the class. +[`BaseElement::getCMSEditLink()`](api:DNADesign\Elemental\Models\BaseElement::getCMSEditLink()) relies on a valid CMS link being available in the parent `DataObject` - in this case, `BlogPost`. It is used to navigate directly to the editing section of the particular element. > [!NOTE] > If you have a nested [`GridField`](api:SilverStripe\Forms\GridField\GridField) this method can get more complicated. Similarly, if your class is used in multiple admins, you will have to choose one to be the canonical admin section for the purposes of this method. This example only shows the simplest case, where the `BlogPost` class is used directly in `BlogPostsAdmin`. @@ -68,7 +68,7 @@ class BlogPost extends DataObject { // ... - public function CMSEditLink() + public function getCMSEditLink(): ?string { // In this example we use BlogPostsAdmin class as Controller $admin = BlogPostsAdmin::singleton(); diff --git a/src/Forms/ElementalAreaField.php b/src/Forms/ElementalAreaField.php index 845de3bf..e1c1bb77 100644 --- a/src/Forms/ElementalAreaField.php +++ b/src/Forms/ElementalAreaField.php @@ -167,7 +167,7 @@ protected function getReadOnlyBlockReducer() 'ElementTitle' => $element->Title, 'ElementEditLink' => Controller::join_links( // Always get the edit link for the block directly, not the in-line edit form if supported - $element->CMSEditLink(true), + $element->getCMSEditLink(true), '#Root_History' ), ], diff --git a/src/Models/BaseElement.php b/src/Models/BaseElement.php index 513f4085..44bf4513 100644 --- a/src/Models/BaseElement.php +++ b/src/Models/BaseElement.php @@ -886,7 +886,7 @@ public function isCMSPreview() * @return null|string * @throws \SilverStripe\ORM\ValidationException */ - public function CMSEditLink($directLink = false) + public function getCMSEditLink($directLink = false): ?string { // Allow for repeated calls to be returned from cache if (isset($this->cacheData['cms_edit_link'])) { @@ -919,10 +919,14 @@ private function getElementCMSLink(bool $directLink) } if ($page instanceof SiteTree) { - $link = $page->CMSEditLink(); - } elseif (ClassInfo::hasMethod($page, 'CMSEditLink')) { - $link = Controller::join_links($page->CMSEditLink(), 'ItemEditForm'); + $link = $page->getCMSEditLink(); + } else { + $baseLink = $page->getCMSEditLink(); + if ($baseLink) { + $link = Controller::join_links($baseLink, 'ItemEditForm'); + } } + // In-line editable blocks should just take you to the page. // Editable ones should add the suffix for detail form. if (!$this->inlineEditable() || $directLink) { @@ -937,7 +941,7 @@ private function getElementCMSLink(bool $directLink) 'edit' ); } else { - // If $page is not a Page, then generate $link base on $page->CMSEditLink() + // If $page is not a Page, then generate $link base on $page->getCMSEditLink() return Controller::join_links( $link, 'field', @@ -1015,7 +1019,7 @@ public function unsanitiseClassName($class, $delimiter = '-') */ public function getEditLink() { - return Director::absoluteURL((string) $this->CMSEditLink()); + return Director::absoluteURL((string) $this->getCMSEditLink()); } /** @@ -1028,7 +1032,7 @@ public function PageCMSEditLink() if ($page = $this->getPage()) { return DBField::create_field('HTMLText', sprintf( '%s', - $page->CMSEditLink(), + $page->getCMSEditLink(), $page->Title )); } diff --git a/src/Models/ElementalArea.php b/src/Models/ElementalArea.php index 183064c8..92008390 100644 --- a/src/Models/ElementalArea.php +++ b/src/Models/ElementalArea.php @@ -147,7 +147,7 @@ public function Breadcrumbs() if ($owner = $ownerClassName::get()->filter('ElementalAreaID', $this->ID)->first()) { return DBField::create_field('HTMLText', sprintf( '%s', - $owner->CMSEditLink(), + $owner->getCMSEditLink(), $owner->Title )); } diff --git a/src/Reports/ElementsInUseReport.php b/src/Reports/ElementsInUseReport.php index cd8d6b1f..67f2a4d8 100644 --- a/src/Reports/ElementsInUseReport.php +++ b/src/Reports/ElementsInUseReport.php @@ -53,7 +53,7 @@ public function columns() $value = $item->Title; if (!empty($value)) { - if ($link = $item->CMSEditLink()) { + if ($link = $item->getCMSEditLink()) { return $this->getEditLink($value, $link); } return $value; @@ -88,7 +88,7 @@ public function columns() 'title' => _t(__CLASS__ . '.Page', 'Page'), 'formatting' => function ($value, BaseElement $item) { if ($value) { - if ($link = $item->getPage()->CMSEditLink()) { + if ($link = $item->getPage()->getCMSEditLink()) { return $this->getEditLink($value, $link); } } diff --git a/templates/DNADesign/Elemental/Models/BaseElement_EditorPreview.ss b/templates/DNADesign/Elemental/Models/BaseElement_EditorPreview.ss index c39556fc..8d92962c 100644 --- a/templates/DNADesign/Elemental/Models/BaseElement_EditorPreview.ss +++ b/templates/DNADesign/Elemental/Models/BaseElement_EditorPreview.ss @@ -1,5 +1,5 @@