Version: current

     1 <?php
     2 /**
     3  * Creates an editable field that displays members in a given group
     4  *
     5  * @package userforms
     6  */
     7
     8 class EditableMemberListField extends EditableFormField {
     9
    10     static $singular_name = 'Member List Field';
    11
    12     static $plural_name = 'Member List Fields';
    13
    14     function getFieldConfiguration() {
    15         $groupID = ($this->getSetting('GroupID')) ? $this->getSetting('GroupID') : 0;
    16         $groups = DataObject::get("Group");
    17
    18         if($groups) $groups = $groups->toDropdownMap('ID', 'Title');
    19
    20         $fields = new FieldSet(
    21             new DropdownField("Fields[$this->ID][CustomSettings][GroupID]", _t('EditableFormField.GROUP', 'Group'), $groups, $groupID)
    22         );
    23
    24         return $fields;
    25     }
    26
    27     function getFormField() {
    28         if ($this->getSetting('GroupID')) {
    29             $members = Member::mapInGroups($this->getSetting('GroupID'));
    30
    31             return new DropdownField($this->Name, $this->Title, $members);
    32         }
    33
    34         return false;
    35     }
    36
    37     function getValueFromData($data) {
    38         if(isset($data[$this->Name])) {
    39             $value = Convert::raw2sql($data[$this->Name]);
    40
    41             $member = DataObject::get_one('Member', "Member.ID = {$value}");
    42
    43             return ($member) ? $member->getName() : "";
    44         }
    45
    46         return false;
    47     }
    48 }

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