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.

All other Modules /

Discuss all other Modules here.

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

Associating DataObjects to Subsite


Reply


4 Posts   1547 Views

Avatar
Hubertus

Community Member, 14 Posts

28 June 2009 at 4:30am

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!

Avatar
Sam

Administrator, 685 Posts

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.

Avatar
Hubertus

Community Member, 14 Posts

5 July 2009 at 4:18am

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

Avatar
Hauke

Community Member, 2 Posts

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?

Thanks
Hauke