Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

bluehousegroup/silverstripe-data-object-version-viewer

Repository files navigation

Data Object Version Viewer

Screenshot

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.