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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Value of SimpleTreeDropdownField in DataObjectManager is not being saved

Go to End

4 Posts   1181 Views


Community Member, 19 Posts

23 April 2010 at 10:08am

Edited: 23/04/2010 10:16am

I created a DataObjectManager for managing "help links". These are featured links to other pages which are shown on some of the pages of a client's website. The structure I want to achieve is the following:

<h2>I need help with...</h2>
<h3><a href="product-foo">Product Foo</a></h3>
<p>This is the description of product foo.</p>
<h3><a href="product-bar">Product Bar</a></h3>
<p>This is the description of product bar.</p>

I appended the DataObjectManager to the HomePage in the CMS, since there is only one homepage, and I use the homepage for all content which is not a page and not related to specific page types. I have the following code so far:



class HomePage extends Page
	public static $db = array(
		"Introduction" => "HTMLText"
	public static $has_one = array(
	static $has_many = array(
		"Helplinks" => "Helplink"
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->removeFieldFromTab("Root.Content.Main", "Content");
		$fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("Introduction"));
		$fields->addFieldToTab("Root.Content.Helplinks", new DataObjectManager(
				"Title" => "Title",
				"Description" => "Description"
		return $fields;

class HomePage_Controller extends Page_Controller
	function LatestNewsArticles($num = 3)
		$news_articles = DataObject::get_one("NewsPageHolder");
		return ($news_articles) ? DataObject::get("NewsPage", "ParentID = $news_articles->ID", "Date DESC", "", $num) : false;
	function PartnerSpotlight()
		$partner = DataObject::get_one("PartnerPage", null, false, "RAND()");
		return $partner;
	function LatestCases($num = 3)
		$cases = DataObject::get_one("CasePageHolder");
		return ($cases) ? DataObject::get("CasePage", "ParentID = $cases->ID", "Created DESC", "", $num) : false;




class Helplink extends DataObject
	static $db = array(
		"Title" => "Varchar(255)",
		"Description" => "Text"
	static $has_one = array(
		"LinkTo" => "SiteTree",
		"HomePage" => "HomePage"
	public function getCMSFields_forPopup()
		$fields = new FieldSet();
		$title = new TextField("Title");
		$description = new TextareaField("Description");
		$pages = new SimpleTreeDropdownField("LinkTo", "Choose a page:", "SiteTree");
		$pages->setEmptyString("-- Select a page --");
		return $fields;


I use a SimpleTreeDropdownField for selecting a page from the SiteTree to link to.

The problem is that the title and description fields are being saved, but not the link. In the database the field LinkToID always contains "1", the ID of the HomePage in the SiteTree table.

When I use $pages = new SimpleTreeDropdownField("LinkToID", "Choose a page:", "SiteTree"); instead of $pages = new SimpleTreeDropdownField("LinkTo", "Choose a page:", "SiteTree");, the DataObjectManager doesn't show the SimpleTreeDropdownField.

What am I doing wrong?


Forum Moderator, 4102 Posts

23 April 2010 at 12:01pm

LinkToID is correct. Usually when the field doesn't appear, it means you have already added a field to your form with that name. Double check your code.


Community Member, 19 Posts

23 April 2010 at 7:09pm

Edited: 23/04/2010 7:09pm

Thank you for your feedback UncleCheese.

Unfortunatly, the SimpleTreeDropdownField still doesn't show. The following code is generated in the DataObjectManager popup:

			<div class="field text " id="Title"><label for="DataObjectManager_Popup_AddForm_Title" class="left">Title</label><div class="middleColumn"><input type="text" value="" name="Title" id="DataObjectManager_Popup_AddForm_Title" class="text"></div></div>
			<div class="field textarea " id="Description"><label for="DataObjectManager_Popup_AddForm_Description" class="left">Description</label><div class="middleColumn"><textarea cols="20" rows="5" name="Description" id="DataObjectManager_Popup_AddForm_Description"></textarea></div></div>
			<input type="hidden" value="Helplink" name="ctf[ClassName]" id="DataObjectManager_Popup_AddForm_ctf-ClassName" class="hidden">
			<input type="hidden" value="HomePage" name="ctf[parentClass]" id="DataObjectManager_Popup_AddForm_ctf-parentClass" class="hidden">
			<input type="hidden" value="Helplinks" name="ctf[hasManyRelation]" id="DataObjectManager_Popup_AddForm_ctf-hasManyRelation" class="hidden">
			<input type="hidden" value="1" name="ctf[sourceID]" id="DataObjectManager_Popup_AddForm_ctf-sourceID" class="hidden">
			<input type="hidden" value="1" name="LinkToID" id="DataObjectManager_Popup_AddForm_LinkToID" class="hidden">
			<input type="hidden" value="2085569391" name="SecurityID" id="DataObjectManager_Popup_AddForm_SecurityID" class="hidden">
		<div class="clear"><!-- --></div>

So there is a field LinkToID, but it's a hidden field, not a SimpleTreeDrowndownField with the SiteTree.


Forum Moderator, 4102 Posts

24 April 2010 at 1:31am

Yeah, that's why it's not showing. Check your code and make sure you have your model set up correctly. That hidden field shouldn't be there. The lazy way to fix it is to just change the name of your has_one relation from LInkTo to something new, but you should really figure out where that legacy relational data is coming from.