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

ModelAdmin Relations


Reply

5 Posts   509 Views

Avatar
markpatella

28 September 2011 at 10:43pm Community Member, 4 Posts

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

Avatar
swaiba

28 September 2011 at 11:36pm Forum Moderator, 1796 Posts

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

Avatar
markpatella

29 September 2011 at 12:07am Community Member, 4 Posts

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

Avatar
swaiba

29 September 2011 at 12:19am Forum Moderator, 1796 Posts

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));

Avatar
markpatella

29 September 2011 at 12:41am Community Member, 4 Posts

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