2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableDropdown
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
2010-09-03 07:06:13 +02:00
|
|
|
* Represents a modifiable dropdown (select) box on a form
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
2009-12-07 03:04:20 +01:00
|
|
|
|
2009-04-17 04:26:40 +02:00
|
|
|
class EditableDropdown extends EditableMultipleOptionField {
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $singular_name = 'Dropdown Field';
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
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;
|
|
|
|
}
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2010-09-03 07:06:13 +02:00
|
|
|
/**
|
|
|
|
* @return DropdownField
|
|
|
|
*/
|
2015-07-24 04:37:48 +02:00
|
|
|
public function getFormField() {
|
2015-08-10 07:03:36 +02:00
|
|
|
$field = DropdownField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap());
|
2010-09-03 07:06:13 +02:00
|
|
|
|
2015-08-10 07:03:36 +02:00
|
|
|
// Set default
|
|
|
|
$defaultOption = $this->getDefaultOptions()->first();
|
|
|
|
if($defaultOption) {
|
|
|
|
$field->setValue($defaultOption->EscapedTitle);
|
2009-04-17 04:26:40 +02:00
|
|
|
}
|
2015-08-10 07:03:36 +02:00
|
|
|
$this->doUpdateFormField($field);
|
2014-12-22 02:49:33 +01:00
|
|
|
return $field;
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
2009-12-07 03:04:20 +01:00
|
|
|
}
|