Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Draft mode for DataObject?


Go to End


12 Posts   8015 Views

Avatar
andy_steel

Community Member, 31 Posts

2 October 2009 at 4:47am

Hi,

We are currently using relationships between "SiteTree" and "DataObject" classes. The only problem with this is that when someone makes changes to the data stored in the "DataObject" classes, it is immediately publishes live to the web. Our CMS users are familiar with the concept of drafts and they wonder why changes to data objects are published immediately.

What is the best way of making a draft mode for a DataObject? Simply having an additional "draft" field in the DataObject is not enough since a draft page should relate to a draft object, and a published page should relate to a published object.

Thanks,
Andy

Avatar
Willr

Forum Moderator, 5523 Posts

2 October 2009 at 4:35pm

You can add the 'Versioned' extension to the dataobject.

// your dataobject
static $extensions = array(
	"Versioned('Stage', 'Live')"
);

See how far you get with that, with UserForms I had to also override several functions which versioned didn't seem to have any effect. Namely overriding doPublish() on the Page (not the dataobject) to publish the DataObjects (which where in a has_many). An example from UserForms...

// your page type
public function doPublish() {
	// publish the draft form fields..
	if($this->Fields()) {
		foreach($this->Fields() as $field) {
		$field->publish('Stage', 'Live');
		}
	}

	parent::doPublish();
}

Avatar
andy_steel

Community Member, 31 Posts

5 October 2009 at 9:22pm

Thanks willr. I wasn't aware of the Versioned extension. I'll give that a try.

Avatar
freefall

Community Member, 5 Posts

4 February 2010 at 12:13pm

Hi Willr,

I have tried adding the Versioned extension to the my DataObject, and when I do dev/build the _versions & _Live tables are created.

When I save (not save and publish) my data object gets a new version placed in the _versions table. Save and publish does nothing as you mentioned.

When I try to add the following code:

// your page type 
public function doPublish() { 
   // publish the draft form fields.. 
   if($this->Fields()) { 
      foreach($this->Fields() as $field) { 
      $field->publish('Stage', 'Live'); 
      } 
   }

   parent::doPublish(); 
}

I get an error saving page when trying to Save & Publish. I am just wondering if there was any additional code required.

Cheers,

Avatar
atomicguava

Community Member, 3 Posts

25 May 2010 at 2:58am

Edited: 25/05/2010 2:59am

I've been wondering exactly the same question - is draft mode possible for dataobjects?

The code posted here didn't work for me either (Silverstripe 2.3.3) - I get the error message like FreeFall.

Any help would be greatly appreciated.

Avatar
Willr

Forum Moderator, 5523 Posts

25 May 2010 at 9:31am

The doPublish function has to be on your pagetype (not the dataobject) since all the publishing functionality is tied to pages you need to publish the dataobjects from a page. A reference of this is the userdefinedform module. UserDefinedForm has the doPublish() which goes through each object calling publish() the functionality. Some minor discussion about abstracting this process out - http://open.silverstripe.org/ticket/5609

Avatar
atomicguava

Community Member, 3 Posts

26 May 2010 at 3:24am

Edited: 26/05/2010 3:24am

Thanks Willr,

I have a HomePage which extends Page (Page extends SiteTree). Homepage has_many Tag.

I added the 'dopublish' code which you suggested into the HomePage.php file (not in the controller section, but the main HomePage class).

I get the following error when doing a save and publish in the CMS:

500 Error: "Uncaught Exception: Object->__call(): the method 'fields' does not exist on 'HomePage'" at line 551 of /Users/xxxx/Sites/xxxx/cms/sapphire/core/Object.php

Any ideas as to why this doesn't work?

Avatar
Mo

Community Member, 541 Posts

5 August 2010 at 12:57am

Hi All,

I am having a bit of a nightmare getting this to work. I have created a dataobject extension, added the versioned extension, then added the doPublish method to my "HomePage" class.

No matter what I do, doPublish does not seem to be being called. I have also altered doPublish to onAfterPublish, but that also has no effect.

Silverstripe tells me it has published fine, but I cannot generate any error messages or debugging info.

Help?!

Mo

Go to Top