Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Does anybody know how to iterate DataObject::database_fields

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 481 Views
  • CMSPlayer
    Avatar
    Community Member
    25 Posts

    Does anybody know how to iterate DataObject::database_fields Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Does anybody know how to iterate DataObject::database_fields Link to this post

    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.

  • CMSPlayer
    Avatar
    Community Member
    25 Posts

    Re: Does anybody know how to iterate DataObject::database_fields Link to this post

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

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