10994 Posts in 2728 Topics by 1819 members
|Go to End|
28 June 2009 at 4:30am
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!
28 June 2009 at 12:17pm
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.
5 July 2009 at 4:18am
Thanks a lot, this worked! Maybe this could be added to the Wiki ...
12 August 2009 at 4:06am
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?
|Go to Top|