tag.
*
* Setting a $has_one relation
*
* Using here an example of an art gallery, with Exhibition pages,
* each of which has a Gallery they belong to. The Gallery class is also user-defined.
*
* static $has_one = array(
* 'Gallery' => 'Gallery',
* );
*
* public function getCMSFields() {
* $fields = parent::getCMSFields();
* $galleries = DataObject::get('Gallery');
* if ($galleries) {
* $galleries = $galleries->toDropdownMap('ID', 'Title', '(Select one)', true);
* }
* $fields->addFieldToTab('Root.Content.Main', new DropdownField('GalleryID', 'Gallery', $galleries), 'Content');
*
*
* As you see, you need to put "GalleryID", rather than "Gallery" here.
*
* Populate with Array
*
* Example model defintion:
*
* class MyObject extends DataObject {
* static $db = array(
* 'Country' => "Varchar(100)"
* );
* }
*
*
* Exampe instantiation:
*
* new DropdownField(
* 'Country',
* 'Country',
* array(
* 'NZ' => 'New Zealand',
* 'US' => 'United States'
* 'GEM'=> 'Germany'
* )
* );
*
*
* Populate with Enum-Values
*
* You can automatically create a map of possible values from an {@link Enum} database column.
*
* Example model definition:
*
* class MyObject extends DataObject {
* static $db = array(
* 'Country' => "Enum('New Zealand,United States,Germany','New Zealand')"
* );
* }
*
*
* Field construction:
*
* new DropdownField(
* 'Country',
* 'Country',
* singleton('MyObject')->dbObject('Country')->enumValues()
* );
*
*
* @package forms
* @subpackage fields-basic
*/
class DropdownField extends FormField {
/**
* @var boolean $source Associative or numeric array of all dropdown items,
* with array key as the submitted field value, and the array value as a
* natural language description shown in the interface element.
*/
protected $source;
/**
* @var boolean $isSelected Determines if the field was selected
* at the time it was rendered, so if {@link $value} matches on of the array
* values specified in {@link $source}
*/
protected $isSelected;
/**
* @var boolean $disabled
*/
protected $disabled;
/**
* @var boolean $hasEmptyDefault Show the first