Trying ModelAdmin on for size
I have lately been doing quite a bit of work using the SilverStripe CMS, which also has a built in development framework, Sapphire. This is the open source child of SilverStripe, a local company here in Wellington.
Version 2.3.0 of SilverStripe comes with a stable version of ModelAdmin, a really handy new tool I have been playing with in the CVS version prior to release. You can see a video of Ingo Schommer from SilverStripe giving an overview of ModelAdmin here. He also has the bones of the presentation up on Slideshare which isn’t as long but you don’t get to have Ingo’s germanic voice caress your ears.
Issues:
HTMLText fields
Modeladmin does not seem to like HTMLText dataobject fields at the moment and their corresponding form field types, HtmlEditorField. In my local WAMP this causes an page to pretened to load for eternity (though I gave up after about 90 secs so cannot fully confirm the eternity thing…).
I don’t see this as a major issue: html fields are best suited to the Site Content tab where all that stuff currently takes place anyway. There seems to be a bug report in for this issue anyway.
Scaffolding
ModelAdmin makes it super easy to give your data a CRUD (Create, Read, Update Delete – thanks Ingo!) interface. If you have a dataobject with defined relationships (has_one, has_many or many_many), ModelAdmin will create these as drop down lists in your create/edit forms right off the bat.
This is super but right away I noticed a problem: these drop down lists for component dataobjects have no sorting on them. Thus my list of 2,500 New Zealand towns was not in alphabetical order. Far from ideal.
You can work around this by defining your own form via a getCMSFields function for the dataobject. This allows you to populate your drop down fields via DataObject::get, allowing you a much greater level of control.
Tip 1: make sure you define it as a new fieldset: $fields = new FieldSet();
Tip 2: use fields->push: $fields->push(new DropdownField(‘MyDataID’,'My Data’,$MyArray->toDropDownMap(‘ID’, ‘Name’)));
Tip 3: See I used MyDataID as the field name where the field is called MyData. This had me confused for a bit as ModelAdmin was not capturing the input when I was calling the field MyData.
Assuming you avoid the pitfalls I made above, you can create a dataobject, set it up in ModelAdmin, and in 5mins have a back end administration area for your new data object. Fantastic!
Quite often when I encounter these types of “one size fits all” dataobject management tools, they always lack just enough to put you off using them, but I think ModelAdmin passes with flying colours. It is already being tried out in two websites under development.
