Jump to:

23364 Posts in 18125 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Draft mode for DataObject?

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

Page: 1 2
Go to End
Author Topic: 4153 Views
  • andy_steel
    Avatar
    Community Member
    31 Posts

    Draft mode for DataObject? Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Draft mode for DataObject? Link to this post

    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();
    }

  • andy_steel
    Avatar
    Community Member
    31 Posts

    Re: Draft mode for DataObject? Link to this post

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

  • freefall
    Avatar
    Community Member
    5 Posts

    Re: Draft mode for DataObject? Link to this post

    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,

  • atomicguava
    Avatar
    Community Member
    3 Posts

    Re: Draft mode for DataObject? Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Draft mode for DataObject? Link to this post

    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

  • atomicguava
    Avatar
    Community Member
    3 Posts

    Re: Draft mode for DataObject? Link to this post

    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?

  • Mo
    Avatar
    Community Member
    504 Posts

    Re: Draft mode for DataObject? Link to this post

    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

    4153 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.