2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\Forms;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Single checkbox field.
|
|
|
|
*/
|
|
|
|
class CheckboxField extends FormField {
|
2009-04-29 03:20:24 +02:00
|
|
|
|
2016-03-21 11:12:23 +01:00
|
|
|
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_SINGLESELECT;
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setValue($value) {
|
2009-04-29 03:20:24 +02:00
|
|
|
$this->value = ($value) ? 1 : 0;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2009-04-29 03:20:24 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function dataValue() {
|
2011-05-23 10:36:20 +02:00
|
|
|
return ($this->value) ? 1 : NULL;
|
2009-04-29 03:20:24 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Value() {
|
2009-04-29 03:20:24 +02:00
|
|
|
return ($this->value) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getAttributes() {
|
2011-12-22 13:10:57 +01:00
|
|
|
$attrs = parent::getAttributes();
|
|
|
|
$attrs['value'] = 1;
|
|
|
|
return array_merge(
|
|
|
|
$attrs,
|
|
|
|
array(
|
|
|
|
'checked' => ($this->Value()) ? 'checked' : null,
|
|
|
|
'type' => 'checkbox',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a readonly version of this field
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function performReadonlyTransformation() {
|
2012-03-24 01:17:48 +01:00
|
|
|
$field = new CheckboxField_Readonly($this->name, $this->title, $this->value);
|
2007-07-19 12:40:28 +02:00
|
|
|
$field->setForm($this->form);
|
2014-08-15 08:53:05 +02:00
|
|
|
return $field;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|