Giter VIP home page Giter VIP logo

silverstripe-versioneddataobjects's Introduction

SilverStripe Versioned DataObjects

This module provides an easy to use implementation of SilverStripe's built-in Versioned extension for DataObjects, along with admin components to manage your versioned things.

Versioned DataObject Example Versioned DataObject Example 2

Installation (with composer)

$ composer require heyday/silverstripe-versioneddataobjects

Usage

The VersionedDataObject extension adds the same draft/published versioning used for pages to your own DataObjects, and any subclasses they have. Only fields in the table of a DataObject with this extension will be versioned. Related DataObjects need VersionedDataObject applied separately if required.

class Slice extends DataObject
{
	private static $db = [
		'Content' => 'Text'
	];

	private static $has_one = [
		'Parent' => 'SiteTree'
	];

	private static $extensions = [
		'Heyday\VersionedDataObjects\VersionedDataObject'
	];
}

Versioned DataObjects in a GridField

To use VersionedDataObject records in a GridField, GridFieldDetailForm needs to be replaced with VersionedDataObjectDetailsForm:

// ...

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 Heyday\VersionedDataObjects\VersionedDataObjectDetailsForm());

	return $fields;
}

// ...

Versioned DataObjects in a ModelAdmin

class SliceAdmin extends VersionedModelAdmin
{
	private static $menu_title = 'Slices';

	private static $url_segment = 'slice';

	private static $managed_models = [
		'Slice'
	];
}

Cavets / Troubleshooting

SilverStripe's versioning system uses global state to keep track of a "reading mode" that affects which tables records are read from and written to for all uses of the Versioned extension. This works on the front end of a site where you expect to see the currently selected stage, however it also alters what records are visible in the CMS if not adjusted for. The admin components supplied with this module work around this to always show draft records in the CMS.

If you have control over an ORM query, you can alter the behaviour of Versioned with DataQuery parameters to override the global reading mode setting:

VersionedFoo::get()
	->setDataQueryParam(['Versioned.stage' => 'Stage']);

If you can't modify a query, you can use VersionedReadingMode from this module to change and restore the global reading mode around a piece of code:

VersionedReadingMode::setStageReadingMode();

// ... code that runs queries

VersionedReadingMode::restoreOriginalReadingMode();

If you suspect you might be seeing an issue from incorrect reading mode, the global reading mode can be changed between live and stage by adding the query string ?stage=Stage or ?stage=Live to the current URL.

BetterButtons compatibility

This module works with unclecheese/betterbuttons version 1.2.8.

Unit testing

None :(

##License

SilverStripe Versioned DataObjects is licensed under an MIT license

silverstripe-versioneddataobjects's People

Contributors

stecman avatar camspiers avatar glenn-bautista avatar alex-dna avatar tylerkidd avatar christopherdarling avatar jakeb-blissmedia avatar stevie-mayhew avatar assertchris avatar azt3k avatar

Watchers

James Cloos avatar Bram de Leeuw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.