Jump to:

3461 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Extending page versioning to data objects

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

Page: 1
Go to End
Author Topic: 1617 Views
  • Tom B.
    Avatar
    Community Member
    5 Posts

    Extending page versioning to data objects Link to this post

    Hi, on our site's HomePage we have a custom DataObject called a "HomePageTab" which is just a little container with 3 news items in it. The problem is that editing these tabs in a draft will alter the tab on the published page as well. Our editors want to be able to see how the tabs look in a draft before publishing them.

    I've tried adding this to HomePageTab but it didn't seem to help:

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

    I've also tried moving HomePage's "has_many HomePageTab" into "has_one HomePageTab" but that just breaks the page.

    I'm probably missing something incredibly obvious here, so apologies. It's my first post :o]

    Here are the relevant bits of HomePage and HomePageTab (I think):

    class HomePage extends Page {

    static $allowed_children = array(
    'HomePageTab',
    'Tag',
    'PopularDocument',
    );

    static $has_one = array(
    );

    static $has_many = array(
    'Tabs' => 'HomePageTab',
    'TagCloud' => 'Tag',
    'PopularDocuments' => 'PopularDocument',
    );
    }

    class HomePageTab extends DataObject {
    static $db = array(
    'Title' => 'Varchar',
    'ColumnOneText' => 'Varchar(255)',
    'ColumnTwoText' => 'Varchar(255)',
    'ColumnThreeText' => 'Varchar(255)',
    'ColumnOneLink' => 'Varchar(255)',
    'ColumnTwoLink' => 'Varchar(255)',
    'ColumnThreeLink' => 'Varchar(255)',
    'ColumnOneLinkTarget' => "Enum('_parent, _blank','_parent')",
    'ColumnTwoLinkTarget' => "Enum('_parent, _blank','_parent')",
    'ColumnThreeLinkTarget' => "Enum('_parent, _blank','_parent')",
    );
    static $has_one = array(
    'HomePage' => 'HomePage',
    'ColumnOneImage' => 'Image',
    'ColumnTwoImage' => 'Image',
    'ColumnThreeImage' => 'Image',
    );
    }

  • mark_s
    Avatar
    Community Member
    78 Posts

    Re: Extending page versioning to data objects Link to this post

    Hi. I don't think you're missing anything obvious. It's versioning, it's not obvious

    You're right that you need to apply the Versioned decorator to HomePageTab, but you'll need to do more than that. There is a logical relationship between the HomePage versions and HomePageTab versions. Each HomePageTab version relates to a HomePage version. When a HomePage is published, you'll need to trigger publishing of the HomePageTab objects associated with it at the same time.

    You can define an onAfterPublish() function on HomePage which selects the HomePageTab objects associated with the current HomePage object, and publishes them if they are not already published. I hope that makes sense. You need to be careful about which versions of HomePageTab you're dealing with - you want to select draft objects in the onAfterPublish, and publish them. On the front end, be sure that live versions are being selected (you can verify this by adding ?showqueries=1 to the URL, and examining the SQL statements being issued)

    Hope this helps.

    Mark

  • Tom B.
    Avatar
    Community Member
    5 Posts

    Re: Extending page versioning to data objects Link to this post

    Thank you so much! I'll have a go at this later.

    1617 Views
Page: 1
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.