2017 © Pedro Peláez
 

silverstripe-module silverstripe-versioneddataobjects

Provides Versioned DataObjects in SilverStripe

image

heyday/silverstripe-versioneddataobjects

Provides Versioned DataObjects in SilverStripe

  • Tuesday, November 28, 2017
  • by heyday
  • Repository
  • 26 Watchers
  • 21 Stars
  • 58,732 Installations
  • PHP
  • 14 Dependents
  • 2 Suggesters
  • 22 Forks
  • 4 Open issues
  • 26 Versions
  • 7 % Grown

The README.md

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., (*1)

IMPORTANT: Versioning of DataObjects is built-in to the Versioned extension in SilverStripe 4.x and newer., (*2)

Versioned DataObject Example Versioned DataObject Example 2, (*3)

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., (*4)

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:, (*5)

// ...

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 Heyday\VersionedDataObjects\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., (*6)

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:, (*7)

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:, (*8)

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., (*9)

BetterButtons compatibility

This module works with unclecheese/betterbuttons version 1.2.8., (*10)

Unit testing

None :(, (*11)

License

SilverStripe Versioned DataObjects is licensed under an MIT license, (*12)

The Versions

28/11 2017

dev-master

9999999-dev

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

21/03 2017

2.0.5

2.0.5.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

21/03 2017

2.0.4

2.0.4.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

18/10 2016

2.0.3

2.0.3.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

17/10 2016

2.0.2

2.0.2.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

05/10 2016

2.0.1

2.0.1.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

29/06 2016

2.0.0

2.0.0.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

02/04 2016

1.5.0

1.5.0.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

29/03 2016

dev-readme-spruce

dev-readme-spruce

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

17/11 2015

1.4.0

1.4.0.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

08/11 2015

1.3.3

1.3.3.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

05/11 2015

1.3.2

1.3.2.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

05/11 2015

1.3.1

1.3.1.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

02/11 2015

1.3.0

1.3.0.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

28/10 2015

v1.2.3

1.2.3.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

20/10 2015

1.2.2

1.2.2.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

14/10 2015

1.2.1

1.2.1.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

07/10 2015

1.2.0

1.2.0.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

06/10 2015

1.1.3

1.1.3.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

01/10 2015

1.1.2

1.1.2.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

16/09 2015

1.1.1

1.1.1.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

19/06 2015

1.1.0

1.1.0.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

24/04 2015

1.0.3

1.0.3.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

07/03 2015

1.0.2

1.0.2.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

24/03 2014

1.0.1

1.0.1.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires

22/07 2013

1.0.0

1.0.0.0

Provides Versioned DataObjects in SilverStripe

  Sources   Download

The Requires

 

The Development Requires