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 @@
- href="$CMSEditLink"<% end_if %> class="elemental-edit"> + href="$getCMSEditLink"<% end_if %> class="elemental-edit">
$Icon
diff --git a/tests/BaseElementTest.php b/tests/BaseElementTest.php index ad6ce471..2540a9be 100644 --- a/tests/BaseElementTest.php +++ b/tests/BaseElementTest.php @@ -342,7 +342,7 @@ public function getElementCMSLinkDataProvider() 'admin/pages/edit/EditForm/1/field/ElementalArea/item/1/edit', true ], - // DataObject without CMSEditLink method + // DataObject without getCMSEditLink method implemented 'element6' => [ TestElement::class, 'elementDataObject2', @@ -354,10 +354,10 @@ public function getElementCMSLinkDataProvider() /** * @dataProvider getElementCMSLinkDataProvider */ - public function testCMSEditLink(string $class, string $element, ?string $link, bool $directLink = false) + public function testGetCMSEditLink(string $class, string $element, ?string $link, bool $directLink = false) { $object = $this->objFromFixture($class, $element); - $editLink = $object->CMSEditLink($directLink); + $editLink = $object->getCMSEditLink($directLink); if ($link) { $this->assertStringContainsString($link, $editLink); diff --git a/tests/ElementalAreaDataObjectTest.yml b/tests/ElementalAreaDataObjectTest.yml index 43b34f57..e7fd4657 100644 --- a/tests/ElementalAreaDataObjectTest.yml +++ b/tests/ElementalAreaDataObjectTest.yml @@ -17,12 +17,12 @@ DNADesign\Elemental\Models\ElementalArea: DNADesign\Elemental\Tests\Src\TestDataObjectWithCMSEditLink: dataObject1: - Title: DataObject with CMSEditLink method + Title: DataObject with getCMSEditLink method ElementalAreaID: =>DNADesign\Elemental\Models\ElementalArea.areaDataObject1 DNADesign\Elemental\Tests\Src\TestDataObject: dataObject2: - Title: DataObject without CMSEditLink, Link, or PreviewLink methods + Title: DataObject without getCMSEditLink, Link, or PreviewLink methods ElementalAreaID: =>DNADesign\Elemental\Models\ElementalArea.areaDataObject2 DNADesign\Elemental\Tests\Src\TestPreviewableDataObject: diff --git a/tests/Src/TestDataObjectWithCMSEditLink.php b/tests/Src/TestDataObjectWithCMSEditLink.php index 75da7b98..dc58ccdb 100644 --- a/tests/Src/TestDataObjectWithCMSEditLink.php +++ b/tests/Src/TestDataObjectWithCMSEditLink.php @@ -27,7 +27,7 @@ class TestDataObjectWithCMSEditLink extends DataObject implements TestOnly 'ElementalArea', ]; - public function CMSEditLink() + public function getCMSEditLink(): ?string { $link = Controller::join_links( 'admin/', diff --git a/tests/Src/TestPreviewableDataObject.php b/tests/Src/TestPreviewableDataObject.php index c38101fd..e03b71bc 100644 --- a/tests/Src/TestPreviewableDataObject.php +++ b/tests/Src/TestPreviewableDataObject.php @@ -19,7 +19,7 @@ public function getMimeType() return null; } - public function CMSEditLink() + public function getCMSEditLink(): ?string { return null; }