diff --git a/src/Forms/DropdownField.php b/src/Forms/DropdownField.php index 765b8a9df31..10db5f65820 100644 --- a/src/Forms/DropdownField.php +++ b/src/Forms/DropdownField.php @@ -2,145 +2,316 @@ namespace SilverStripe\Forms; -use SilverStripe\ORM\ArrayList; -use SilverStripe\View\ArrayData; +use ArrayAccess; +use SilverStripe\ORM\Map; +use SilverStripe\ORM\SS_List; +use SilverStripe\Core\Convert; +use SilverStripe\ORM\FieldType\DBHTMLText; /** - * Dropdown field, created from a select 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(); - * $field = DropdownField::create('GalleryID', 'Gallery', Gallery::get()->map('ID', 'Title')) - * ->setEmptyString('(Select one)'); - * $fields->addFieldToTab('Root.Content', $field, 'Content'); - * - * - * As you see, you need to put "GalleryID", rather than "Gallery" here. - * - * Populate with Array - * - * Example model definition: - * - * class MyObject extends DataObject { - * static $db = array( - * 'Country' => "Varchar(100)" - * ); - * } - * - * - * Example instantiation: - * - * DropdownField::create( - * '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: - * - * DropdownField::create( - * 'Country', - * 'Country', - * singleton('MyObject')->dbObject('Country')->enumValues() - * ); - * - * - * Disabling individual items - * - * Individual items can be disabled by feeding their array keys to setDisabledItems. - * - * - * $DrDownField->setDisabledItems( array( 'US', 'GEM' ) ); - * - * - * @see CheckboxSetField for multiple selections through checkboxes instead. - * @see ListboxField for a single