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.
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
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.
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.
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...?