Version: current

     1 <?php
     2 /**
     3  * EditableCheckbox
     4  *
     5  * A user modifiable checkbox on a UserDefinedForm
     6  *
     7  * @package userforms
     8  */
     9
    10 class EditableCheckbox extends EditableFormField {
    11
    12     static $singular_name = 'Checkbox Field';
    13
    14     static $plural_name = 'Checkboxes';
    15
    16     public function getFieldConfiguration() {
    17         $options = parent::getFieldConfiguration();
    18         $options->removeByName("Fields[$this->ID][CustomSettings][Placeholder]");
    19         $options->push(new CheckboxField("Fields[$this->ID][CustomSettings][Default]", _t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?'), $this->getSetting('Default')));
    20
    21         return $options;
    22     }
    23
    24     public function getFormField() {
    25         return new CheckboxField( $this->Name, $this->Title, $this->getSetting('Default'));
    26     }
    27
    28     public function getValueFromData($data) {
    29         $value = (isset($data[$this->Name])) ? $data[$this->Name] : false;
    30
    31         return ($value) ? _t('EditableFormField.YES', 'Yes') : _t('EditableFormField.NO', 'No');
    32     }
    33 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -