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.

Customising the CMS

Admin DropDown for ParentPage of DataObject


Reply

4 Posts   921 Views

Avatar
monkee

24 February 2011 at 10:52am (Last edited: 24 February 2011 10:55am), Community Member, 20 Posts

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

24 February 2011 at 8:18pm Forum Moderator, 5511 Posts

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

17 March 2011 at 3:13pm (Last edited: 17 March 2011 3:14pm), Community Member, 20 Posts

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

17 March 2011 at 5:03pm (Last edited: 17 March 2011 5:09pm), Community Member, 20 Posts

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!