Version: current

     1 <?php
     2 /**
     3  * EditableCheckboxGroup
     4  *
     5  * Represents a set of selectable radio buttons
     6  *
     7  * @package userforms
     8  */
     9
    10 class EditableCheckboxGroupField extends EditableMultipleOptionField {
    11
    12     static $singular_name = "Checkbox Group";
    13
    14     static $plural_name = "Checkbox Groups";
    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][ArrangeInLine]", _t('EditableCheckboxGroupField.ArrangeInLine', 'Arrange in line?'), $this->getSetting('ArrangeInLine')));
    20
    21         return $options;
    22     }
    23
    24     function getFormField() {
    25         $optionSet = $this->Options();
    26         $options = array();
    27
    28         $optionMap = ($optionSet) ? $optionSet->map('Title', 'Title') : array();
    29
    30         $field = new CheckboxSetField($this->Name, $this->Title, $optionMap);
    31         if ($this->getSetting('ArrangeInLine')) {
    32             $field->addExtraClass('in_line');
    33         }
    34         return $field;
    35     }
    36
    37     function getValueFromData($data) {
    38         $result = '';
    39         $entries = (isset($data[$this->Name])) ? $data[$this->Name] : false;
    40
    41         if($entries) {
    42             if(!is_array($data[$this->Name])) {
    43                 $entries = array($data[$this->Name]);
    44             }
    45             foreach($entries as $selected => $value) {
    46                 if(!$result) {
    47                     $result = $value;
    48                 } else {
    49                     $result .= ", " . $value;
    50                 }
    51             }
    52         }
    53         return $result;
    54     }
    55
    56     function getArrangeInLine() {
    57         return $this->getSetting('ArrangeInLine');
    58     }
    59 }

[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. -