7912 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Value of SimpleTreeDropdownField in DataObjectManager is not being saved
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 902 Views |
-
Value of SimpleTreeDropdownField in DataObjectManager is not being saved

23 April 2010 at 10:08am Last edited: 23 April 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:
HomePage.php
<?php
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(
$this,
"Helplinks",
"Helplink",
array(
"Title" => "Title",
"Description" => "Description"
),
'getCMSFields_forPopup'
));
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;
}
}?>
Helplink.php
<?php
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");
$fields->push($title);
$description = new TextareaField("Description");
$fields->push($description);
$pages = new SimpleTreeDropdownField("LinkTo", "Choose a page:", "SiteTree");
$pages->setEmptyString("-- Select a page --");
$fields->push($pages);
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?
-
Re: Value of SimpleTreeDropdownField in DataObjectManager is not being saved

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.
-
Re: Value of SimpleTreeDropdownField in DataObjectManager is not being saved

23 April 2010 at 7:09pm Last edited: 23 April 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:
<fieldset>
<legend></legend>
<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>
</fieldset>So there is a field LinkToID, but it's a hidden field, not a SimpleTreeDrowndownField with the SiteTree.
-
Re: Value of SimpleTreeDropdownField in DataObjectManager is not being saved

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.
| 902 Views | ||
|
Page:
1
|
Go to Top |

