bluehousegroup / silverstripe-data-object-version-viewer
Allows viewing of version history for data objects inside of the SilverStripe CMS
Installs: 12 890
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 18
Forks: 7
Open Issues: 7
Type:silverstripe-module
Requires
This package is auto-updated.
Last update: 2021-12-17 08:08:10 UTC
README
Install with Composer
composer require bluehousegroup/silverstripe-data-object-version-viewer
Usage
- 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
Example code
The implementation is very similar to the versioneddataobjects module, on which this module depends.
Within your DataObject class
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; } // ...
Versioned DataObjects in a ModelAdmin
class SliceAdmin extends VersionedRevertModelAdmin { private static $menu_title = 'Slices'; private static $url_segment = 'slice'; private static $managed_models = [ 'Slice' ]; }
Notes
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.