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

ModelAdmin Relations


Go to End


5 Posts   1107 Views

Avatar
markpatella

Community Member, 4 Posts

28 September 2011 at 10:43pm

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

Forum Moderator, 1899 Posts

28 September 2011 at 11:36pm

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

Community Member, 4 Posts

29 September 2011 at 12:07am

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

Forum Moderator, 1899 Posts

29 September 2011 at 12:19am

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

Community Member, 4 Posts

29 September 2011 at 12:41am

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