mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
This commit is contained in:
parent
ecc619248b
commit
6b1dfddcb8
@ -57,6 +57,49 @@ Versioning only works if you are adding the extension to the base class. That is
|
||||
of `DataObject`. Adding this extension to children of the base class will have unpredictable behaviour.
|
||||
</div>
|
||||
|
||||
## Versioned gridfield extension
|
||||
|
||||
By default the versioned module includes a `VersionedGridfieldDetailForm` that can extend gridfield
|
||||
with versioning support for models.
|
||||
|
||||
You can enable this on a per-model basis using the following code:
|
||||
|
||||
```php
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
class MyBanner extends DataObject {
|
||||
private static $extensions = [
|
||||
Versioned::class,
|
||||
];
|
||||
private static $versioned_gridfield_extensions = true;
|
||||
}
|
||||
```
|
||||
|
||||
This can be manually enabled for a single gridfield, alternatively, by setting the following option on the
|
||||
GridFieldDetailForm component.
|
||||
|
||||
```php
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
|
||||
use SilverStripe\Forms\GridField\GridFieldDetailForm;
|
||||
use SilverStripe\Versioned\VersionedGridFieldItemRequest;
|
||||
class Page extends SiteTree
|
||||
{
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
$config = GridFieldConfig_RelationEditor::create();
|
||||
$config
|
||||
->getComponentByType(GridFieldDetailForm::class)
|
||||
->setItemRequestClass(VersionedGridFieldItemRequest::class);
|
||||
$gridField = GridField::create('Items', 'Items', $this->Items(), $config);
|
||||
$fields->addFieldToTab('Root.Items', $gridField);
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Database Structure
|
||||
|
||||
Depending on whether staging is enabled, one or more new tables will be created for your records. `<class>_versions`
|
||||
@ -217,7 +260,6 @@ without requiring any custom code.
|
||||
'Image'
|
||||
];
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Note that ownership cannot be used with polymorphic relations. E.g. has_one to non-type specific `DataObject`.
|
||||
@ -265,7 +307,6 @@ E.g.
|
||||
return MyParent::get()->first();
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
#### DataObject Ownership in HTML Content
|
||||
@ -333,7 +374,6 @@ E.g.
|
||||
return Permission::checkMember($member, 'ADMIN');
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
If you want to control permissions of an object in an extension, you can also use
|
||||
@ -376,7 +416,6 @@ E.g.
|
||||
];
|
||||
private static $non_live_permissions = ['ADMIN'];
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Versioned applies no additional permissions to `canEdit` or `canCreate`, and such
|
||||
|
Loading…
x
Reference in New Issue
Block a user