Inheritance: extends FormField
 /**
  * Hook into the updateProfileFields function to swap out the email field with our own custom Field.
  * @param  FieldList $fields
  */
 public function updateProfileFields(FieldList $fields)
 {
     // Get a reference to the MemberProfilePage
     $owner = $this->getOwner();
     // Get the Email Profile Field
     $profileField = $owner->Fields()->filter(array('MemberField' => 'Email'))->first();
     if (!$profileField || !$profileField->ID || $profileField->AllowedDomains && $profileField->DisallowedDomains) {
         // If we can't find the Email Profile Field or if there's no domain condition on the field,
         // there's no point carrying on
         return;
     }
     // Get the actual Email Form Field
     $oldField = $fields->fieldByName('Email');
     if (!$oldField) {
         // IF we can't find the form field.
         return;
     }
     // The form field might come as a CheckableVisibilityField or a TextField.
     // We need to handle both case differently
     if (is_a($oldField, 'CheckableVisibilityField')) {
         // Create our new DomainSpecificEmailField
         $field = $this->initNewField($oldField->getChild(), $profileField);
         // We need to replicate a bit of logic from MembrProfilePage::getProfileFields()
         $field = new CheckableVisibilityField($field);
         if ($profileField->PublicVisibility == 'Display') {
             $field->makeAlwaysVisible();
         } else {
             $field->getCheckbox()->setValue($profileField->PublicVisibilityDefault);
         }
     } else {
         // Just convert the Email Form Field to our DomainSpecificEmailField
         $field = $this->initNewField($oldField, $profileField);
     }
     // Swap our the old field with the new one.
     $fields->replaceField('Email', $field);
 }
 /**
  * @param  string $context
  * @return FieldSet
  */
 protected function getProfileFields($context)
 {
     $profileFields = $this->Fields();
     $fields = new FieldList();
     // depending on the context, load fields from the current member
     if (Member::currentUser() && $context != 'Add') {
         $memberFields = Member::currentUser()->getMemberFormFields();
     } else {
         $memberFields = singleton('Member')->getMemberFormFields();
     }
     // use the default registration fields for adding members
     if ($context == 'Add') {
         $context = 'Registration';
     }
     if ($this->AllowProfileViewing && $profileFields->find('PublicVisibility', 'MemberChoice')) {
         $fields->push(new LiteralField('VisibilityNote', '<p>' . _t('MemberProfiles.CHECKVISNOTE', 'Check fields below to make them visible on your public ' . 'profile.') . '</p>'));
     }
     foreach ($profileFields as $profileField) {
         $visibility = $profileField->{$context . 'Visibility'};
         $name = $profileField->MemberField;
         $memberField = $memberFields->dataFieldByName($name);
         // handle the special case of the Groups control so that only allowed groups can be selected
         if ($name == 'Groups') {
             $availableGroups = $this->data()->SelectableGroups();
             $memberField->setSource($availableGroups);
         }
         if (!$memberField || $visibility == 'Hidden') {
             continue;
         }
         $field = clone $memberField;
         if ($visibility == 'Readonly') {
             $field = $field->performReadonlyTransformation();
         }
         $field->setTitle($profileField->Title);
         $field->setDescription($profileField->Note);
         if ($context == 'Registration' && $profileField->DefaultValue) {
             $field->setValue($profileField->DefaultValue);
         }
         if ($profileField->CustomError) {
             $field->setCustomValidationMessage($profileField->CustomError);
         }
         $canSetVisibility = $this->AllowProfileViewing && $profileField->PublicVisibility != 'Hidden';
         if ($canSetVisibility) {
             $field = new CheckableVisibilityField($field);
             if ($profileField->PublicVisibility == 'Display') {
                 $field->makeAlwaysVisible();
             } else {
                 $field->getCheckbox()->setValue($profileField->PublicVisibilityDefault);
             }
         }
         $fields->push($field);
     }
     $this->extend('updateProfileFields', $fields);
     return $fields;
 }
 /**
  * @param  string $context
  * @return FieldSet
  */
 protected function getProfileFields($context)
 {
     $profileFields = $this->Fields();
     $fields = new FieldSet();
     // depending on the context, load fields from the current member
     if (Member::currentUser() && $context != 'Add') {
         $memberFields = Member::currentUser()->getMemberFormFields();
     } else {
         $memberFields = singleton('Member')->getMemberFormFields();
     }
     if ($context == 'Registration') {
         $fields->push(new HeaderField('LogInHeader', _t('MemberProfiles.LOGIN_HEADER', 'Log In')));
         $fields->push(new LiteralField('LogInNote', '<p>' . sprintf(_t('MemberProfiles.LOGIN', 'If you already have an account you can <a href="%s">log in here</a>.'), Security::Link('login') . '?BackURL=' . $this->Link()) . '</p>'));
         $fields->push(new HeaderField('RegisterHeader', _t('MemberProfiles.REGISTER', 'Register')));
     }
     if ($context == 'Profile' && $this->AllowAdding && singleton('Member')->canCreate()) {
         $fields->push(new HeaderField('AddHeader', _t('MemberProfiles.ADDUSER', 'Add User')));
         $fields->push(new LiteralField('AddMemberNote', '<p>' . sprintf(_t('MemberProfiles.ADDMEMBERNOTE', 'You can use this page to <a href="%s">add a new member</a>.'), $this->Link('add')) . '</p>'));
         $fields->push(new HeaderField('YourProfileHeader', _t('MemberProfiles.YOURPROFILE', 'Your Profile')));
     }
     // use the default registration fields for adding members
     if ($context == 'Add') {
         $context = 'Registration';
     }
     if ($this->AllowProfileViewing && $profileFields->find('PublicVisibility', 'MemberChoice')) {
         $fields->push(new LiteralField('VisibilityNote', '<p>' . _t('MemberProfiles.CHECKVISNOTE', 'Check fields below to make them visible on your public ' . 'profile.') . '</p>'));
     }
     foreach ($profileFields as $profileField) {
         $visibility = $profileField->{$context . 'Visibility'};
         $name = $profileField->MemberField;
         $memberField = $memberFields->dataFieldByName($name);
         // handle the special case of the Groups control so that only allowed groups can be selected
         if ($name == 'Groups') {
             $availableGroups = $this->data()->SelectableGroups();
             $memberField->setSource($availableGroups);
         }
         if (!$memberField || $visibility == 'Hidden') {
             continue;
         }
         $field = clone $memberField;
         if ($visibility == 'Readonly') {
             $field = $field->performReadonlyTransformation();
         }
         $field->setTitle($profileField->Title);
         $field->setRightTitle($profileField->Note);
         if ($context == 'Registration' && $profileField->DefaultValue) {
             $field->setValue($profileField->DefaultValue);
         }
         if ($profileField->CustomError) {
             $field->setCustomValidationMessage($profileField->CustomError);
         }
         $canSetVisibility = $this->AllowProfileViewing && $profileField->PublicVisibility != 'Hidden';
         if ($canSetVisibility) {
             $field = new CheckableVisibilityField($field);
             if ($profileField->PublicVisibility == 'Display') {
                 $field->makeAlwaysVisible();
             } else {
                 $field->getCheckbox()->setValue($profileField->PublicVisibilityDefault);
             }
         }
         $fields->push($field);
     }
     $this->extend('updateProfileFields', $fields);
     return $fields;
 }