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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

ManyMany Complex Table Field -- Setting Default Checked Checkboxes

Go to End

3 Posts   3265 Views


Community Member, 14 Posts

23 July 2008 at 12:56am

Edited: 23/07/2008 2:24am


If got a problem with the ManyManyComplexTableField.
I'm trying to find out how to make certain Entries constantly checked.

I have a Pagetype "Faq" that is always Child of "ThemeHolder".
"Faq" represents an Question-Answer pair that was made.
"ThemeHolder" represents the Themes that the Faq entry can belong to.
In the ManyMany ComplexTableField theres a List of all "ThemeHolders" and you can correlate "Faq" with multiple "ThemeHolders".

Now I want that the "ThemeHolder" that is the parent to "Faq" is always checked and is not to change by the CMS user.
All the other ones can be checked or unchecked as normal but this one correlation has to be always there, otherwise it makes no sense.
Cause I want to make it possible that a Faq entry is able to correspond to many Themes, but the Theme it is Child of should always be checked and unable to get unchecked.

Is there anyone who might can help me with this Problem?
I would be very thankful!


Community Member, 14 Posts

30 July 2008 at 4:03am

Edited: 30/07/2008 4:05am

Well... finally I got the answer to my Problem. In any case someone is interessted what I've done let you know here:

class Faq extends Page
	static $many_many = array(
		'Themes' => 'ThemeHolder' //Relations name is "Themes"
        protected $myThemeArray = array();
	protected $myString = "";
//WHATCH OUT: The function onAfterWrite() is only useable when you use the Daily builds, it's not included in the Version 2.2.2
        function onAfterWrite()
		$myID = $this->ParentID;
		$myThemes = $this->Themes(); //be shure to use the Name here you gave your many_many relation before
	function getMyParents($myID)
		if( DataObject::get_by_id('SiteTree', $myID))
			$myObj = DataObject::get_by_id('SiteTree', $myID);
			if( $myObj->ClassName != 'FaqHolder' )
				$myThemeID = $myObj->ID;
				$this->myThemeArray[] = $myThemeID;
				foreach($this->myThemeArray as $PID)
					$this->myString .= $PID;
				$myParentID = $myObj->ParentID;


As you hoefully have noticed is that the Function onAfterWrite() is beeing used. This is only availeble when you use the Daily builds. I don't know since when it isicluded, just use the newest one.


The problem was that with the function onBeforeWrite() you are unable to use $this->ID or $this->ParentID, because the actual entry hasn't been made yet, as you are Before the writing progress...

That way I have all my Themes Selected by default, even when someone deselects them, they will be there the next time he visits the Many_Many Table.

If anyone is interested in the FAQ Module I'm creating just let me know.



Community Member, 14 Posts

20 August 2008 at 2:42am

Edited: 20/08/2008 2:43am

Hi RNHurt!

Sorry that I took so long to answer your question!
Well, I think what you have in mind is something completely different than my FAQ.
I have actually build something very untypical, for that my FAQ looks more like an Forum.
You can make up themes and Subthemes and make your FAQ posts there.
The main idea was to make an FAQ that we in our development Team can make entries to specific themes, so if another one has the same issue he can look it up fast.
An FAQ like you see it on most of the Pages with a list of about 10 questions and beneath all the Question/Answer pairs, with the back to top links etc. isn't what I had to develop.

But if you have some more infos in what your problem is, I can try to help you.

For now I would suggest to make one Page that "holds" all the FAQ entries.
So you can easly list them on top and afterward make a clear Template for them.
For example:


So that MyFAQ is the Parent.
Now you can use the to <% control Children %> and firstly give out a list of Questions with the link to them.
and afterwards another control to give out the complete Question/Answer pair.
So you could work with anchors in your templates that makes it easy to jump around in the site.

Could I help you with this?

Best wishes,