2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableCheckbox
|
2012-04-14 08:36:50 +02:00
|
|
|
*
|
2008-09-29 05:18:23 +02:00
|
|
|
* A user modifiable checkbox on a UserDefinedForm
|
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
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
class EditableCheckbox extends EditableFormField {
|
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $singular_name = 'Checkbox Field';
|
2008-09-29 05:18:23 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $plural_name = 'Checkboxes';
|
2015-07-24 04:37:48 +02:00
|
|
|
|
|
|
|
private static $db = array(
|
|
|
|
'CheckedDefault' => 'Boolean' // from CustomSettings
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields() {
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
|
|
|
|
$fields->replaceField('Default', CheckboxField::create(
|
|
|
|
"CheckedDefault",
|
|
|
|
_t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?')
|
|
|
|
));
|
|
|
|
|
|
|
|
return $fields;
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2009-04-27 08:00:05 +02:00
|
|
|
public function getFormField() {
|
2015-08-10 07:03:36 +02:00
|
|
|
$field = CheckboxField::create($this->Name, $this->EscapedTitle, $this->CheckedDefault);
|
|
|
|
$this->doUpdateFormField($field);
|
2014-12-22 02:49:33 +01:00
|
|
|
return $field;
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
2009-05-06 05:34:40 +02:00
|
|
|
|
|
|
|
public function getValueFromData($data) {
|
|
|
|
$value = (isset($data[$this->Name])) ? $data[$this->Name] : false;
|
2010-09-08 05:20:28 +02:00
|
|
|
|
2009-05-06 05:34:40 +02:00
|
|
|
return ($value) ? _t('EditableFormField.YES', 'Yes') : _t('EditableFormField.NO', 'No');
|
|
|
|
}
|
2015-07-24 04:37:48 +02:00
|
|
|
|
|
|
|
public function migrateSettings($data) {
|
|
|
|
// Migrate 'Default' setting to 'CheckedDefault'
|
|
|
|
if(isset($data['Default'])) {
|
|
|
|
$this->CheckedDefault = (bool)$data['Default'];
|
|
|
|
unset($data['Default']);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::migrateSettings($data);
|
|
|
|
}
|
|
|
|
}
|