2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
2017-08-09 01:55:09 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\UserForms\Model\EditableFormField;
|
|
|
|
|
|
|
|
use SilverStripe\Forms\CheckboxField;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
/**
|
|
|
|
* EditableCheckbox
|
2012-04-14 08:36:50 +02:00
|
|
|
*
|
2008-09-29 05:18:23 +02:00
|
|
|
* A user modifiable checkbox on a UserDefinedForm
|
2015-09-11 00:20:06 +02:00
|
|
|
*
|
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
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
class EditableCheckbox extends EditableFormField
|
|
|
|
{
|
|
|
|
private static $singular_name = 'Checkbox Field';
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
private static $plural_name = 'Checkboxes';
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2017-04-28 00:22:15 +02:00
|
|
|
protected $jsEventHandler = 'click';
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $db = [
|
2016-07-21 07:53:59 +02:00
|
|
|
'CheckedDefault' => 'Boolean' // from CustomSettings
|
2017-08-11 01:33:06 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
private static $table_name = 'EditableCheckbox';
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields()
|
|
|
|
{
|
|
|
|
$fields = parent::getCMSFields();
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
$fields->replaceField('Default', CheckboxField::create(
|
|
|
|
"CheckedDefault",
|
2017-08-11 01:33:06 +02:00
|
|
|
_t('SilverStripe\\UserForms\\Model\\EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?')
|
2016-07-21 07:53:59 +02:00
|
|
|
));
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
return $fields;
|
|
|
|
}
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
public function getFormField()
|
|
|
|
{
|
|
|
|
$field = CheckboxField::create($this->Name, $this->EscapedTitle, $this->CheckedDefault)
|
2017-08-14 02:29:57 +02:00
|
|
|
->setFieldHolderTemplate(__CLASS__ . '_holder')
|
|
|
|
->setTemplate(__CLASS__);
|
2015-08-21 05:21:33 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
$this->doUpdateFormField($field);
|
2015-08-21 05:21:33 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
return $field;
|
|
|
|
}
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
public function getValueFromData($data)
|
|
|
|
{
|
|
|
|
$value = (isset($data[$this->Name])) ? $data[$this->Name] : false;
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
return ($value)
|
|
|
|
? _t('SilverStripe\\UserForms\\Model\\EditableFormField.YES', 'Yes')
|
|
|
|
: _t('SilverStripe\\UserForms\\Model\\EditableFormField.NO', 'No');
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
2015-07-24 04:37:48 +02:00
|
|
|
|
2017-08-11 02:37:03 +02:00
|
|
|
public function isCheckBoxField()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2015-07-24 04:37:48 +02:00
|
|
|
}
|