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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

How to create an empty DropDownField ? Error in DataObjectManager.php on line 584

Go to End

3 Posts   1403 Views


Community Member, 47 Posts

3 April 2010 at 8:48pm

I populate a DropDownField automatically from an array as :

function getCMSFields() {

$fields = new FieldSet( new DropdownField(
'Choose a country',
Dataobject::get("country")->toDropdownMap("CountryName", "CountryName")
), ..etc ..

This works very well when 'country' already contains data. However I get an error when at init. there
is **no country** yet in the database.

I understand this is because Dataobject::get() is NULL and therefore the call to toDropdownMap fails.

So I tried to use a function which tests if 'country' is empty or not :

function CreateCountryList() {
$myDataSet = DataObject::get("country");
if (!$myDataSet) return false;
return $myDataSet->toDropdownMap("CountryName", "CountryName");

$fields = new FieldSet( new DropdownField(
'Choose a country',

But with that, I can not properly create a country for the customer with the DOM. (i.e the entry is written in the DB but the DOM
does not display it in the table and returns the error messages :

ERROR [Warning]: Missing argument 3 for ComplexTableField_Item::__construct(), called in /home/www/ on line 584 and defined
IN POST /admin/getitem?ID=11&ajax=1
Line 980 in /home/www/

I guess my CreateCountryList() is wrong so my question is to create an empty DropDownField ?

I hope this is not too confusing ...

Thanks in advance for any tip,


PS. I am running SS 2.3.7 with the latest DOM ( March 23 )


Forum Moderator, 4102 Posts

4 April 2010 at 2:21am

If you're running SS 2.3, you need to use the 2.3 branch of DOM. See the "2.3 branch" sticky.

Never, ever, ever run a function directly against a query. If it comes back false, you get a fatal error, like you're seeing.

$map = ($set = DataObject::get("MyThing")) ? $set->toDropdownMap() : array();

new DropdownField('Foo','Bar',$map);


Community Member, 47 Posts

4 April 2010 at 9:53am

Thank you very much for the tip : I used your code **and** I downloaded the 2.3 version of the DOM (I was running the 2.4 from the
Modules page ) and it works fine.
Thanks again - Lise