composer require bluehousegroup/silverstripe-data-object-version-viewer
- Extend
silverstripe-versioneddataobjects
to add a 'History' button to a GridField or ModelAdmin - View, revert to, and publish a previous versions of a data object
The implementation is very similar to the versioneddataobjects module, on which this module depends.
class Slice extends DataObject
{
private static $db = [
'Content' => 'Text'
];
private static $has_one = [
'Parent' => 'SiteTree'
];
private static $extensions = [
'Heyday\VersionedDataObjects\VersionedDataObject'
];
}
To use VersionedDataObject
records in a GridField, GridFieldDetailForm
needs to be replaced with VersionedRevertDODetailsForm
:
// ...
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab(
'Root.Slices',
new GridField(
'Slices',
'Slices',
$this->Slices(),
$config = GridFieldConfig_RelationEditor::create()
)
);
$config->removeComponentsByType('GridFieldDetailForm');
$config->addComponent(new VersionedRevertDODetailsForm());
return $fields;
}
// ...
class SliceAdmin extends VersionedRevertModelAdmin
{
private static $menu_title = 'Slices';
private static $url_segment = 'slice';
private static $managed_models = [
'Slice'
];
}
This module is intended to be compatible with the betterbuttons module. Toward that end, it removes the betterbuttons's Versioning button group in order to keep in tact the buttons added by the versiondataobjects plug-in. This change affects only the forms configured with the VersionedRevertDODetailsForm extension.