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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

Does anybody know how to iterate DataObject::database_fields


Go to End


3 Posts   1432 Views

Avatar
CMSPlayer

Community Member, 25 Posts

10 April 2012 at 6:05pm

What I'm trying to do is to traverse all the elements within this static field arrays of Dataobject and have it prepopulated in a dropdown box.

How do I accomplish this as part of an extension to UDF module's functionality.

Avatar
Willr

Forum Moderator, 5523 Posts

11 April 2012 at 7:12pm

So this is a dropdown the user of the site can select a field from? You'll want to create your own subclass of EditableFormField and override the getFormField() to return your dropdown field populated with the fields. DataObject::database_fields() simply returns a map of names to types so if you want your dropdown to have keys and values of the field name you could do something like following quite easy..

$options = array();
foreach(DataObject::database_fields('Page') as $key => $type) $options[$key] = $key;

return new DropdownField(.., ..., $options);

Have a look at how the other editable form fields work, if you subclass EditableFormField and put your class in the mysite folder SS will automatically pick up the new form field type in the UDF create options.

Avatar
CMSPlayer

Community Member, 25 Posts

14 April 2012 at 1:19am

Pretty much!

With one minor difference - these fields would be used by the CMS administrator, not the web user.

If you ever program VB Access in the old days, you know how every data controls that gets bound by certain data source's record source's properties? In every VB form, you can bind the whole form to an entire table, along with its data controls to their corresponding fields?

That's what I'm trying to here in SS! I want to reproduce that similar experience here in UDF for those UDF's input fields.

I'm very curious how we can port this aspect of VBA's IDE within SS environment...?