Jump to:

5520 Posts in 1734 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » ModelAdmin Relations

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

Page: 1
Go to End
Author Topic: 482 Views
  • markpatella
    Avatar
    Community Member
    4 Posts

    ModelAdmin Relations Link to this post

    Hi,

    i have a DataObject which is managed by ModelAdmin via the cms, so far so good. But all objects that are related to this with a $has_one relation are only shown as DropDownField with the id. How can i customize this to change the DrowDown to other fields from the managed object?

    Thanks a lot for your help!

    mark

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: ModelAdmin Relations Link to this post

    Hi Mark,

    Welcome to the forums!

    I'm not sure what you mean by "How can i customize this to change the DrowDown to other fields from the managed object". Since this is a relationship within the datamodel you are restricted to what can be used... the option I think that might help is the ItemPicker...

    https://github.com/ajshort/silverstripe-itemsetfield

    Also in the situation I what the information edittable after it has been selected I use this...
    http://www.silverstripe.org/data-model-questions/show/13089#post295584

    Hope this helps

    Barry

  • markpatella
    Avatar
    Community Member
    4 Posts

    Re: ModelAdmin Relations Link to this post

    Thanks for your quick reply!

    To clarify it a bit, i have made a screenshot where you can see two DropDownFields with only an id from the relation in it. And i want to change this to another field from the related object.

    mark

  • swaiba
    Avatar
    Forum Moderator
    1785 Posts

    Re: ModelAdmin Relations Link to this post

    Ahhh....

    Where the system is trying to scaffold the drop down it looks for a "Name" field. If you add that then it will look a bit better.

    Alternatively - you could redraw the drop down with the right "Name" (within getCMSFields)

    $dos = DataObject::get($strDataObjectName);
    $map = $dos ? $dos->toDropdownMap('ID','Name') : array(); //change Name in this line
    $fields->replaceField('HasOneID',new DropdownField('HasOneID','Label',$map));

  • markpatella
    Avatar
    Community Member
    4 Posts

    Re: ModelAdmin Relations Link to this post

    Thanks a lot, it works great!

    I had already found the replaceField method but now it ist clear to me how to use it!

    mark

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