public function getCMSFields() { $fields = parent::getCMSFields(); /* * MAIN TAB */ $tab = 'Root.Main'; //provides listbox field menu for selecting a predefined Icon $data = DataObject::get('Icon'); $field = new ListboxField('MyIconID', 'My Icon'); $field->setSource($data->map('ID', 'Name')->toArray()); $field->setEmptyString('Select one'); $fields->addFieldToTab($tab, $field); return $fields; }
/** * * @param Array | SS_Map */ public function setSource($source) { if ($source instanceof SS_Map) { $source = $source->toArray(); } if ($source) { $hasCommas = array_filter(array_keys($source), create_function('$key', 'return strpos($key, ",") !== FALSE;')); if ($hasCommas) { throw new InvalidArgumentException('No commas allowed in $source keys'); } } parent::setSource($source); return $this; }