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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Admin DropDown for ParentPage of DataObject


Go to End


4 Posts   1495 Views

Avatar
monkee

Community Member, 22 Posts

24 February 2011 at 10:52am

Edited: 24/02/2011 10:55am

Following Situation

I have Dataobjects "Project" which have "has_one" relations to "ProjectPage"

following code in the dataobject projects:

public function getCMSFields_forPopup()
 {	
    $pData = (DataObject::get('ProjectPage'));

    if ($pData) {
           $ProjectPageSource = $pData->toDropDownMap();
    }

    $fields->push(new DropdownField(
			'ProjectPage',
		  	'ProjectPage',
		  	$ProjectPageSource,
		        $this
    ));

....}

In the Admin it renders a perfect DropDown List of all my other ProjectPage Pages.
Sadly it never saves!

I think i remember that i'm suppost to use "ProjectPageID" as first Argument to "DropdownFiled" - but then i get an empty DropDown Box.

Where's my Bug?

Thanks a Lot

Avatar
Willr

Forum Moderator, 5523 Posts

24 February 2011 at 8:18pm

I think i remember that i'm suppost to use "ProjectPageID" as first Argument to "DropdownFiled" - but then i get an empty DropDown Box.

You should use the ProjectPageID name for the has_one. It shouldn't stop loading the pages from that as you're passing the pages in manually. Do you get an error when using ProjectPageID?

Avatar
monkee

Community Member, 22 Posts

17 March 2011 at 3:13pm

Edited: 17/03/2011 3:14pm

If i use ProjectPageID the DropDown disapears in Admin with no error message

		$fields->push(new DropdownField(
				'ProjectPageID',
	 		  	'Zugehörige Projektseite auswählen',
	 		  	$ProjectPageSource,
				$this
		));

I am really stuck on this one...

Avatar
monkee

Community Member, 22 Posts

17 March 2011 at 5:03pm

Edited: 17/03/2011 5:09pm

I added the following Workaround to the DataObject!
Like this i am able to reassign the DataObject to a new Page!

public function onBeforeWrite() 
{ 
   $this->ProjectPageID = $this->ProjectPage;
   parent::onBeforeWrite(); 
}

Thanks for all the help on IRC! (especially Willr and DesignCity) You Rock!