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.

General Questions

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

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

Draft mode for DataObject?


Go to End
Reply

12 Posts   4262 Views

Avatar
andy_steel

2 October 2009 at 4:47am Community Member, 31 Posts

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

2 October 2009 at 4:35pm Forum Moderator, 5511 Posts

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

5 October 2009 at 9:22pm Community Member, 31 Posts

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

Avatar
freefall

4 February 2010 at 12:13pm Community Member, 5 Posts

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

25 May 2010 at 2:58am (Last edited: 25 May 2010 2:59am), Community Member, 3 Posts

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

25 May 2010 at 9:31am Forum Moderator, 5511 Posts

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

26 May 2010 at 3:24am (Last edited: 26 May 2010 3:24am), Community Member, 3 Posts

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

5 August 2010 at 12:57am Community Member, 509 Posts

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