Jump to:

10994 Posts in 2728 Topics by 1819 members

All other Modules

SilverStripe Forums » All other Modules » Associating DataObjects to Subsite

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1499 Views
  • Hubertus
    Avatar
    Community Member
    14 Posts

    Associating DataObjects to Subsite Link to this post

    Hello,

    I wonder how to associate DataObjects to Subsites. Essentially, I would like to publish small "newsitems" (DataObjects) on my subsite that are specific to this subsite plus have the option to publish all or some of them on my main site (or any other subsite for that matter).

    Ideally, I'd be able to select what newsitem I want to show on my subsite's homepage through a DataObjectManager and have the same option for the homepage of my main site (select which of the many subsite's newsitems I want to show on the main site homepage).

    I'm also trying to have a Dropdown-Field in my getCMSFields_forPopup() function for the NewsItems that would list the available subsites and allow me to alter the relation and re-assign my NewsItem to another subsite.

    Any hints how this could be done are greatly appreciated!

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Associating DataObjects to Subsite Link to this post

    Right now there's no out-of-the-box way of doing this easily, however, a bit of copy'n'paste should get you what you want.

    The key to how this is done for the pages is subsites/code/SiteTreeSubsites.php. The critical pieces of code that are necessary for making something "subsite aware" are as follows:

    * extraStatics() - adds the SubsiteID field
    * augmentSQL() - filters the queries to only show items from the current subsite
    * First line of augmentBeforeWrite() - sets the subsite ID of newly created pages

    So, if you create a new decorator for your news item objects, and copy and paste those pieces of code into that.

    A sensible refactoring of the subsites module might be to have a 'parent decorator' that SiteTreeSubsites and others inherited from.

  • Hubertus
    Avatar
    Community Member
    14 Posts

    Re: Associating DataObjects to Subsite Link to this post

    Thanks a lot, this worked! Maybe this could be added to the Wiki ...

  • Hauke
    Avatar
    Community Member
    2 Posts

    Re: Associating DataObjects to Subsite Link to this post

    My english is bad and i am a newbie in Silverstripe.

    I want to select the subsites where the newsitems should published. Have you a tutorial for me?

    Thanks
    Hauke

    1499 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.