Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Admin DropDown for ParentPage of DataObject

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

Page: 1
Go to End
Author Topic: 893 Views
  • monkee
    Avatar
    Community Member
    20 Posts

    Admin DropDown for ParentPage of DataObject Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Admin DropDown for ParentPage of DataObject Link to this post

    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?

  • monkee
    Avatar
    Community Member
    20 Posts

    Re: Admin DropDown for ParentPage of DataObject Link to this post

    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...

  • monkee
    Avatar
    Community Member
    20 Posts

    Re: Admin DropDown for ParentPage of DataObject Link to this post

    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!

    893 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.