silverstripe-userforms/code/model/editableformfields/EditableDropdown.php

41 lines
817 B
PHP
Raw Normal View History

<?php
/**
* EditableDropdown
*
* Represents a modifiable dropdown (select) box on a form
*
* @package userforms
*/
class EditableDropdown extends EditableMultipleOptionField {
private static $singular_name = 'Dropdown Field';
private static $plural_name = 'Dropdowns';
2015-07-24 04:37:48 +02:00
/**
* @return FieldList
*/
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeByName('Default');
return $fields;
}
/**
* @return DropdownField
*/
2015-07-24 04:37:48 +02:00
public function getFormField() {
$field = DropdownField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap());
// Set default
$defaultOption = $this->getDefaultOptions()->first();
if($defaultOption) {
$field->setValue($defaultOption->EscapedTitle);
}
$this->doUpdateFormField($field);
return $field;
}
}