2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2009-04-17 04:26:40 +02:00
|
|
|
* EditableRadioField
|
|
|
|
*
|
2008-09-29 05:18:23 +02:00
|
|
|
* Represents a set of selectable radio buttons
|
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 EditableRadioField extends EditableMultipleOptionField {
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $singular_name = 'Radio field';
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $plural_name = 'Radio fields';
|
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
|
|
|
|
2012-07-17 06:09:31 +02:00
|
|
|
public function getFormField() {
|
2008-09-29 05:18:23 +02:00
|
|
|
$optionSet = $this->Options();
|
2015-07-24 04:37:48 +02:00
|
|
|
$defaultOptions = $optionSet->filter('Default', 1);
|
2008-09-29 05:18:23 +02:00
|
|
|
$options = array();
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2009-04-27 08:00:05 +02:00
|
|
|
if($optionSet) {
|
2015-07-24 04:37:48 +02:00
|
|
|
foreach($optionSet as $option) {
|
2013-06-04 07:20:03 +02:00
|
|
|
$options[$option->EscapedTitle] = $option->Title;
|
2015-07-24 04:37:48 +02:00
|
|
|
}
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
2015-07-24 04:37:48 +02:00
|
|
|
|
|
|
|
$field = OptionsetField::create($this->Name, $this->Title, $options);
|
|
|
|
|
|
|
|
if($defaultOptions->count()) {
|
|
|
|
$field->setValue($defaultOptions->First()->EscapedTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $field;
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
2012-07-17 06:09:31 +02:00
|
|
|
}
|