Version: current

     1 <?php
     2
     3 /**
     4  * Base Class for EditableOption Fields such as the ones used in
     5  * dropdown fields and in radio check box groups
     6  *
     7  * @package userforms
     8  */
     9
    10 class EditableOption extends DataObject {
    11
    12     static $default_sort = "Sort";
    13
    14     static $db = array(
    15         "Name" => "Varchar(255)",
    16         "Title" => "Varchar(255)",
    17         "Default" => "Boolean",
    18         "Sort" => "DBInt"
    19     );
    20
    21     static $has_one = array(
    22         "Parent" => "EditableMultipleOptionField",
    23     );
    24
    25     static $extensions = array(
    26         "Versioned('Stage', 'Live')"
    27     );
    28
    29     /**
    30      * Template for the editing view of this option field
    31      */
    32     public function EditSegment() {
    33         return $this->renderWith('EditableOption');
    34     }
    35
    36     /**
    37      * The Title Field for this object
    38      *
    39      * @return FormField
    40      */
    41     public function TitleField() {
    42         return new TextField("Fields[{$this->ParentID}][{$this->ID}][Title]", null, $this->Title );
    43     }
    44
    45     /**
    46      * Name of this field in the form
    47      *
    48      * @return String
    49      */
    50     public function FieldName() {
    51         return "Fields[{$this->ParentID}][{$this->ID}]";
    52     }
    53
    54     /**
    55      * Populate this option from the form field
    56      *
    57      * @param Array Data
    58      */
    59     public function populateFromPostData($data) {
    60         $this->Title = (isset($data['Title'])) ? $data['Title'] : "";
    61         $this->Default = (isset($data['Default'])) ? $data['Default'] : "";
    62         $this->Sort = (isset($data['Sort'])) ? $data['Sort'] : 0;
    63         $this->write();
    64     }
    65
    66     /**
    67      * Make this option readonly
    68      */
    69     public function ReadonlyOption() {
    70         $this->readonly = true;
    71         return $this->EditSegment();
    72     }
    73 }

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