Skip to content

Commit bd63962

Browse files
committed
DOC Document standardised CMSEditLink method
1 parent 097a664 commit bd63962

File tree

5 files changed

+15
-26
lines changed

5 files changed

+15
-26
lines changed

en/02_Developer_Guides/00_Model/13_Managing_Records.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ of some other record or directly [in a ModelAdmin](../customising_the_admin_inte
1212

1313
## Getting an edit link
1414

15+
The [`DataObject::CMSEditLink()`](api:SilverStripe\ORM\DataObject::CMSEditLink()) method will give you the edit link if there is one, but by default it just returns `null`.
16+
1517
There is a [CMSEditLinkExtension](api:SilverStripe\Admin\CMSEditLinkExtension) specifically
1618
for the purpose of generating links to the edit forms of records. It operates on the assumption that your record is being edited in
1719
a [GridFieldDetailForm](../forms/field_types/gridfield#gridfielddetailform) in some `GridField` (be it on another record or in a

en/02_Developer_Guides/14_Files/07_File_Usage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class UsedOnTableExtension extends Extension
5959
// DataObject the File is used on. This is useful for two reasons:
6060
// - It gives context more context, for instance if File is used on a Content block, it can be used to show the
6161
// Page that Content Block is used on
62-
// - The DataObject may not have a `CMSEditLink()` implementation, though the ancestor DataObject does.
62+
// - The DataObject may not return a value from the `CMSEditLink()` method, though the ancestor DataObject does.
6363
// The CMS frontend will fallback to using the Ancestor `CMSEditLink()` for when a user clicks on a row on
6464
// the used on table
6565
protected function updateUsageAncestorDataObjects(array &$ancestorDataObjects, DataObject $dataObject)

en/02_Developer_Guides/15_Customising_the_Admin_Interface/01_ModelAdmin.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ $tabLink = $admin->getLinkForModelTab('product-category');
167167
> [getModelTabForModelClass()](api:SilverStripe\Admin\ModelAdmin::getModelTabForModelClass()) method
168168
> for your `ModelAdmin` subclass.
169169
170-
You can also use the new [CMSEditLinkExtension](api:SilverStripe\Admin\CMSEditLinkExtension) to provide a `CMSEditLink()` method on the record - see [Managing Records](../model/managing_records#getting-an-edit-link).
170+
You can also use the new [CMSEditLinkExtension](api:SilverStripe\Admin\CMSEditLinkExtension) to update the value of the `CMSEditLink()` method on the record - see [Managing Records](../model/managing_records#getting-an-edit-link).
171171

172172
## Permissions
173173

en/02_Developer_Guides/15_Customising_the_Admin_Interface/04_Preview.md

+10-24
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ that is used to manage the object.
5252
This method exists so that when a user clicks on a link in the preview panel, the CMS
5353
edit form for the page the link leads to can be loaded. Unless your `DataObject` is
5454
[acting like a page](https://www.silverstripe.org/learn/lessons/v4/controller-actions-dataobjects-as-pages-1)
55-
this will likely not apply, but as this method is mandatory and public we may as well
56-
set it up correctly.
55+
this will likely not apply.
56+
57+
You can leave the default implementation from `DataObject` which returns `null` if you want.
5758

5859
If your object belongs to [a custom ModelAdmin](./modeladmin), the edit URL for the
5960
object is predictable enough to construct and return from this method as you'll see below.
@@ -63,9 +64,10 @@ nesting `GridField`s. For the below examples it is assumed you aren't using nest
6364
will handle those situations for you if you use it.
6465

6566
> [!TIP]
66-
> The easiest way to implement `CMSEditLink()` is by
67+
> The easiest way to get a correct return value for `CMSEditLink()` is by
6768
> [using CMSEditLinkExtension](/developer_guides/model/managing_records#getting-an-edit-link).
68-
> But for completeness, the other examples below show alternative implementations.
69+
> That extension implements `updateCMSLink()` so you don't have to touch the `CMSEditLink()`
70+
> method directly at all.
6971
>
7072
> ```php
7173
> namespace App\Model;
@@ -83,15 +85,11 @@ will handle those situations for you if you use it.
8385
> CMSEditLinkExtension::class,
8486
> ];
8587
>
86-
> public function CMSEditLink()
87-
> {
88-
> // Get the value returned by the extension
89-
> return $this->extend('CMSEditLink')[0];
90-
> }
91-
>
9288
> // ...
9389
> }
9490
> ```
91+
>
92+
> For completeness, the other examples below show alternative implementations.
9593
9694
#### `GetMimeType`
9795
@@ -192,11 +190,6 @@ class Product extends DataObject implements CMSPreviewable
192190
return $link;
193191
}
194192

195-
public function CMSEditLink()
196-
{
197-
return null;
198-
}
199-
200193
public function getMimeType()
201194
{
202195
return 'text/html';
@@ -523,11 +516,6 @@ class Product extends DataObject implements CMSPreviewable
523516
return $link;
524517
}
525518

526-
public function CMSEditLink()
527-
{
528-
return null;
529-
}
530-
531519
public function getMimeType()
532520
{
533521
return 'text/html';
@@ -592,10 +580,8 @@ class Product extends DataObject implements CMSPreviewable
592580
}
593581
```
594582

595-
The CMSEditLink doesn't matter so much for this implementation. It is required
596-
by the `CMSPreviewable` interface so some implementation must be provided, but
597-
you can safely return `null` or an empty string with no repercussions in this
598-
situation.
583+
The `CMSEditLink()` method doesn't matter so much for this implementation, so you can let
584+
it return the default value of `null`.
599585

600586
#### The page template
601587

en/08_Changelogs/6.0.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ SilverStripe\UserForms\Model\UserDefinedForm:
185185
186186
- Native indexed PHP arrays can now be passed into templates and iterated over with `<% loop $MyArray %>`. Under the hood they are wrapped in [`ArrayList`](api:SilverStripe\View\ViewableData), so you can get the count using `$Count` and use `<% if $ArrayList %>` as a shortcut for `<% if $ArrayList.Count %>`. Other functionality from `ArrayList` such as filtering and sorting cannot be used on arrays since they don't have keys to filter or sort against.
187187
- Modules no longer need to have a root level `_config.php` or `_config` directory to be recognised as a Silverstripe CMS module. They will now be recognised as a module if they have a `composer.json` file with a `type` of `silverstripe-vendormodule` or `silverstripe-theme`.
188+
- A new [`DataObject::CMSEditLink()`](api:SilverStripe\ORM\DataObject::CMSEditLink()) method has been added, which returns `null` by default. This provides more consistency for that method which has previously been inconsistently applied to various subclasses of `DataObject`. See [managing records](/developer_guides/model/managing_records/#getting-an-edit-link) for more details about providing sane values for this method in your own subclasses.
188189

189190
## Dependency changes
190191

0 commit comments

Comments
 (0)