Source of file MemberProfilePage.php
Size: 25,767 Bytes - Last Modified: 2022-02-21T10:00:57+00:00
/var/www/docs.ssmods.com/process/src/code/MemberProfilePage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905 | <?php /** * A MemberProfilePage allows the administratior to set up a page with a subset of the * fields available on the member object, then allow members to register and edit * their profile using these fields. * * Members who have permission to create new members can also be allowed to * create new members via this page. * * It also supports email validation. * * @package silverstripe-memberprofiles */ class MemberProfilePage extends Page implements PermissionProvider { private static $db = array ( 'ProfileTitle' => 'Varchar(255)', 'RegistrationTitle' => 'Varchar(255)', 'AfterRegistrationTitle' => 'Varchar(255)', 'ProfileContent' => 'HTMLText', 'RegistrationContent' => 'HTMLText', 'AfterRegistrationContent' => 'HTMLText', 'AllowRegistration' => 'Boolean', 'AllowProfileViewing' => 'Boolean', 'AllowProfileEditing' => 'Boolean', 'AllowAdding' => 'Boolean', 'RegistrationRedirect' => 'Boolean', 'RequireApproval' => 'Boolean', 'EmailType' => 'Enum("Validation, Confirmation, None", "None")', 'EmailFrom' => 'Varchar(255)', 'EmailSubject' => 'Varchar(255)', 'EmailTemplate' => 'Text', 'ConfirmationTitle' => 'Varchar(255)', 'ConfirmationContent' => 'HTMLText' ); private static $has_one = array( 'PostRegistrationTarget' => 'SiteTree', ); private static $has_many = array ( 'Fields' => 'MemberProfileField', 'Sections' => 'MemberProfileSection' ); private static $many_many = array ( 'Groups' => 'Group', 'SelectableGroups' => 'Group', 'ApprovalGroups' => 'Group' ); private static $defaults = array ( 'ProfileTitle' => 'Edit Profile', 'RegistrationTitle' => 'Register / Log In', 'AfterRegistrationTitle' => 'Registration Successful', 'AfterRegistrationContent' => '<p>Thank you for registering!</p>', 'AllowRegistration' => true, 'AllowProfileViewing' => true, 'AllowProfileEditing' => true, 'ConfirmationTitle' => 'Account Confirmed', 'ConfirmationContent' => '<p>Your account is now active, and you have been logged in. Thankyou!</p>' ); /** * An array of default settings for some standard member fields. * * @var array */ public static $profile_field_defaults = array( 'Email' => array( 'RegistrationVisibility' => 'Edit', 'ProfileVisibility' => 'Edit', 'PublicVisibility' => 'MemberChoice' ), 'FirstName' => array( 'RegistrationVisibility' => 'Edit', 'ProfileVisibility' => 'Edit', 'MemberListVisible' => true, 'PublicVisibility' => 'Display' ), 'Surname' => array( 'RegistrationVisibility' => 'Edit', 'ProfileVisibility' => 'Edit', 'MemberListVisible' => true, 'PublicVisibility' => 'MemberChoice', 'PublicVisibilityDefault' => true ), 'Password' => array( 'RegistrationVisibility' => 'Edit', 'ProfileVisibility' => 'Edit' ) ); private static $description = ''; private static $icon = 'memberprofiles/images/memberprofilepage.png'; /** * If profile editing is disabled, but the current user can add members, * just link directly to the add action. * * @param string $action */ public function Link($action = null) { if( !$action && Member::currentUserID() && !$this->AllowProfileEditing && $this->CanAddMembers() ) { $action = 'add'; } return parent::Link($action); } public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root', new TabSet('Profile', _t('MemberProfiles.PROFILE', 'Profile'))); $fields->addFieldToTab('Root', new Tab('ContentBlocks', _t('MemberProfiles.CONTENTBLOCKS', 'Content Blocks'))); $fields->addFieldToTab('Root', new Tab('Email', _t('MemberProfiles.Email', 'Email'))); $fields->fieldByName('Root.Main')->setTitle(_t('MemberProfiles.MAIN', 'Main')); $fields->addFieldsToTab('Root.Profile', array( new Tab( 'Fields', _t('MemberProfiles.FIELDS', 'Fields'), new GridField( 'Fields', _t('MemberProfiles.PROFILEFIELDS', 'Profile Fields'), $this->Fields(), $grid = GridFieldConfig_RecordEditor::create() ->removeComponentsByType('GridFieldDeleteAction') ->removeComponentsByType('GridFieldAddNewButton') ) ), new Tab( 'Groups', _t('MemberProfiles.GROUPS', 'Groups'), $groups = new TreeMultiselectField( 'Groups', _t('MemberProfiles.GROUPS', 'Groups'), 'Group' ), $selectable = new TreeMultiselectField( 'SelectableGroups', _t('MemberProfiles.SELECTABLEGROUPS', 'Selectable Groups'), 'Group' ) ), new Tab( 'PublicProfile', _t('MemberProfiles.PUBLICPROFILE', 'Public Profile'), new GridField( 'Sections', _t('MemberProfiles.PROFILESECTIONS', 'Profile Sections'), $this->Sections(), GridFieldConfig_RecordEditor::create() ->removeComponentsByType('GridFieldAddNewButton') ->addComponent(new MemberProfilesAddSectionAction()) ) ) )); $grid->getComponentByType('GridFieldDataColumns')->setFieldFormatting(array( 'Unique' => function($val, $obj) { return $obj->dbObject('Unique')->Nice(); }, 'Required' => function($val, $obj) { return $obj->dbObject('Required')->Nice(); } )); if(class_exists('GridFieldOrderableRows')) { $grid->addComponent(new GridFieldOrderableRows('Sort')); } elseif(class_exists('GridFieldSortableRows')) { $grid->addComponent(new GridFieldSortableRows('Sort')); } if(!$this->AllowProfileViewing) { $disabledNote = new LiteralField('PublisProfileDisabledNote', sprintf( '<p class="message notice">%s</p>', _t( 'MemberProfiles.PUBLICPROFILEDISABLED', 'Public profiles are currently disabled, you can enable them ' . 'in the "Settings" tab.' ) )); $fields->insertBefore($disabledNote, 'Sections'); } $groups->setDescription(_t( 'MemberProfiles.GROUPSNOTE', 'Any users registering via this page will always be added to ' . 'these groups (if registration is enabled). Conversely, a member ' . 'must belong to these groups in order to edit their profile on ' . 'this page.' )); $selectable->setDescription(_t( 'MemberProfiles.SELECTABLENOTE', 'Users can choose to belong to these groups, if the "Groups" field ' . 'is enabled in the "Fields" tab.' )); $fields->removeByName('Content', true); $contentFields = array(); if($this->AllowRegistration) { $contentFields[] = 'Registration'; $contentFields[] = 'AfterRegistration'; } if($this->AllowProfileEditing) { $contentFields[] = 'Profile'; } foreach($contentFields as $type) { $fields->addFieldToTab("Root.ContentBlocks", new ToggleCompositeField( "{$type}Toggle", _t('MemberProfiles.'. strtoupper($type), FormField::name_to_label($type)), array( new TextField("{$type}Title", _t('MemberProfiles.TITLE', 'Title')), $content = new HtmlEditorField("{$type}Content", _t('MemberProfiles.CONTENT', 'Content')) ) )); $content->setRows(15); } $fields->addFieldsToTab('Root.Email', array( new OptionsetField( 'EmailType', _t('MemberProfiles.EMAILSETTINGS', 'Email Settings'), array( 'Validation' => _t('MemberProfiles.EMAILVALIDATION', 'Require email validation'), 'Confirmation' => _t('MemberProfiles.EMAILCONFIRMATION', 'Send a confirmation email'), 'None' => _t('MemberProfiles.NONE', 'None') ) ), new ToggleCompositeField('EmailContentToggle', _t('MemberProfiles.EMAILCONTENT', 'Email Content'), array( new TextField('EmailSubject', _t('MemberProfiles.EMAILSUBJECT', 'Email subject')), new TextField('EmailFrom', _t('MemberProfiles.EMAILFROM', 'Email from')), new TextareaField('EmailTemplate', _t('MemberProfiles.EMAILTEMPLATE', 'Email template')), new LiteralField('TemplateNote', sprintf( '<div class="field">%s</div>', MemberConfirmationEmail::TEMPLATE_NOTE )) )), new ToggleCompositeField('ConfirmationContentToggle', _t('MemberProfiles.CONFIRMCONTENT', 'Confirmation Content'), array( new TextField('ConfirmationTitle', _t('MemberProfiles.TITLE', 'Title')), $confContent = new HtmlEditorField('ConfirmationContent', _t('MemberProfiles.CONTENT', 'Content')) )) )); $confContent->setRows(15); return $fields; } public function getSettingsFields() { $fields = parent::getSettingsFields(); $fields->addFieldToTab('Root', new Tab('Profile'), 'Settings'); $fields->addFieldsToTab('Root.Profile', array( new CheckboxField( 'AllowRegistration', _t('MemberProfiles.ALLOWREG', 'Allow registration via this page') ), new CheckboxField( 'AllowProfileEditing', _t('MemberProfiles.ALLOWEDITING', 'Allow users to edit their own profile on this page') ), new CheckboxField( 'AllowAdding', _t('MemberProfiles.ALLOWADD', 'Allow adding members via this page') ), new CheckboxField( 'AllowProfileViewing', _t('MemberProfiles.ALLOWPROFILEVIEWING', 'Enable public profiles?') ), new CheckboxField( 'RequireApproval', _t('MemberProfiles.REQUIREREGAPPROVAL', 'Require registration approval by an administrator?') ), $approval = new TreeMultiselectField( 'ApprovalGroups', _t('MemberProfiles.APPROVALGROUPS', 'Approval Groups'), 'Group' ), new CheckboxField( 'RegistrationRedirect', _t('MemberProfiles.REDIRECTAFTERREG', 'Redirect after registration?') ), new TreeDropdownField( 'PostRegistrationTargetID', _t('MemberProfiles.REDIRECTTOPAGE', 'Redirect To Page'), 'SiteTree' ) )); $approval->setDescription(_t( 'MemberProfiles.NOTIFYTHESEGROUPS', 'These groups will be notified to approve new registrations' )); return $fields; } /** * Get either the default or custom email template. * * @return string */ public function getEmailTemplate() { return ($t = $this->getField('EmailTemplate')) ? $t : MemberConfirmationEmail::DEFAULT_TEMPLATE; } /** * Get either the default or custom email subject line. * * @return string */ public function getEmailSubject() { return ($s = $this->getField('EmailSubject')) ? $s : MemberConfirmationEmail::DEFAULT_SUBJECT; } /** * Returns a list of profile field objects after synchronising them with the * Member form fields. * * @return HasManyList */ public function Fields() { $list = $this->getComponents('Fields'); $fields = singleton('Member')->getMemberFormFields()->dataFields(); $included = array(); foreach($list as $profileField) { if(!array_key_exists($profileField->MemberField, $fields)) { $profileField->delete(); } else { $included[] = $profileField->MemberField; } } foreach($fields as $name => $field) { if(!in_array($name, $included)) { $profileField = new MemberProfileField(); $profileField->MemberField = $name; if(isset(self::$profile_field_defaults[$name])) { $profileField->update(self::$profile_field_defaults[$name]); } $list->add($profileField); } } return $list; } public function onAfterWrite() { if ($this->isChanged('ID', 2)) { $section = new MemberProfileFieldsSection(); $section->ParentID = $this->ID; $section->write(); } parent::onAfterWrite(); } /** * @return bool */ public function CanAddMembers() { return $this->AllowAdding && singleton('Member')->canCreate(); } } /** * */ class MemberProfilePage_Controller extends Page_Controller { private static $allowed_actions = array ( 'index', 'RegisterForm', 'afterregistration', 'ProfileForm', 'add', 'AddForm', 'confirm', 'show' ); /** * @uses MemberProfilePage_Controller::indexRegister * @uses MemberProfilePage_Controller::indexProfile * @return array */ public function index() { if (isset($_GET['BackURL'])) { Session::set('MemberProfile.REDIRECT', $_GET['BackURL']); } $mode = Member::currentUser() ? 'profile' : 'register'; $data = Member::currentUser() ? $this->indexProfile() : $this->indexRegister(); if (is_array($data)) { return $this->customise($data)->renderWith(array('MemberProfilePage_'.$mode, 'MemberProfilePage', 'Page')); } return $data; } /** * Allow users to register if registration is enabled. * * @return array */ protected function indexRegister() { if(!$this->AllowRegistration) return Security::permissionFailure($this, _t ( 'MemberProfiles.CANNOTREGPLEASELOGIN', 'You cannot register on this profile page. Please login to edit your profile.' )); return array ( 'Title' => $this->obj('RegistrationTitle'), 'Content' => $this->obj('RegistrationContent'), 'Form' => $this->RegisterForm() ); } /** * Allows users to edit their profile if they are in at least one of the * groups this page is restricted to, and editing isn't disabled. * * If editing is disabled, but the current user can add users, then they * are redirected to the add user page. * * @return array */ protected function indexProfile() { if(!$this->AllowProfileEditing) { if($this->AllowAdding && Injector::inst()->get('Member')->canCreate()) { return $this->redirect($this->Link('add')); } return Security::permissionFailure($this, _t( 'MemberProfiles.CANNOTEDIT', 'You cannot edit your profile via this page.' )); } $member = Member::currentUser(); foreach($this->Groups() as $group) { if(!$member->inGroup($group)) { return Security::permissionFailure($this); } } $form = $this->ProfileForm(); $form->loadDataFrom($member); if($password = $form->Fields()->fieldByName('Password')) { if ($password->hasMethod('setCanBeEmpty')) { $password->setCanBeEmpty(false); $password->setValue(null); $password->setCanBeEmpty(true); } else { // If Password field is ReadonlyField or similar $password->setValue(null); } } return array ( 'Title' => $this->obj('ProfileTitle'), 'Content' => $this->obj('ProfileContent'), 'Form' => $form ); } /** * @return MemberProfileViewer */ public function show() { if(!$this->AllowProfileViewing) { $this->httpError(404); } return MemberProfileViewer::create($this, 'show'); } /** * @uses MemberProfilePage_Controller::getProfileFields * @return Form */ public function RegisterForm() { $form = new Form ( $this, 'RegisterForm', $this->getProfileFields('Registration'), new FieldList( new FormAction('register', _t('MemberProfiles.REGISTER', 'Register')) ), new MemberProfileValidator($this->Fields()) ); if($form->hasExtension('FormSpamProtectionExtension')) { $form->enableSpamProtection( ); } $this->extend('updateRegisterForm', $form); return $form; } /** * Handles validation and saving new Member objects, as well as sending out validation emails. */ public function register($data, Form $form) { if($member = $this->addMember($form)) { if(!$this->RequireApproval && $this->EmailType != 'Validation' && !$this->AllowAdding) { $member->logIn(); } if ($this->RegistrationRedirect) { if ($this->PostRegistrationTargetID) { $this->redirect($this->PostRegistrationTarget()->Link()); return; } if ($sessionTarget = Session::get('MemberProfile.REDIRECT')) { Session::clear('MemberProfile.REDIRECT'); if (Director::is_site_url($sessionTarget)) { $this->redirect($sessionTarget); return; } } } return $this->redirect($this->Link('afterregistration')); } else { return $this->redirectBack(); } } /** * Returns the after registration content to the user. * * @return array */ public function afterregistration() { return array ( 'Title' => $this->obj('AfterRegistrationTitle'), 'Content' => $this->obj('AfterRegistrationContent') ); } /** * @uses MemberProfilePage_Controller::getProfileFields * @return Form */ public function ProfileForm() { $form = new Form ( $this, 'ProfileForm', $this->getProfileFields('Profile'), new FieldList( new FormAction('save', _t('MemberProfiles.SAVE', 'Save')) ), new MemberProfileValidator($this->Fields(), Member::currentUser()) ); $this->extend('updateProfileForm', $form); return $form; } /** * Updates an existing Member's profile. */ public function save(array $data, Form $form) { $member = Member::currentUser(); $groupIds = $this->getSettableGroupIdsFrom($form, $member); $member->Groups()->setByIDList($groupIds); $form->saveInto($member); try { $member->write(); } catch(ValidationException $e) { $form->sessionMessage($e->getResult()->message(), 'bad'); return $this->redirectBack(); } $form->sessionMessage ( _t('MemberProfiles.PROFILEUPDATED', 'Your profile has been updated.'), 'good' ); return $this->redirectBack(); } /** * Allows members with the appropriate permissions to add/regsiter other * members. */ public function add($request) { if(!$this->AllowAdding || !Injector::inst()->get('Member')->canCreate()) { return Security::permissionFailure($this, _t ( 'MemberProfiles.CANNOTADDMEMBERS', 'You cannot add members via this page.' )); } $data = array( 'Title' => _t('MemberProfiles.ADDMEMBER', 'Add Member'), 'Content' => '', 'Form' => $this->AddForm() ); return $this->customise($data)->renderWith(array('MemberProfilePage_add', 'MemberProfilePage', 'Page')); } /** * @return Form */ public function AddForm() { $form = new Form ( $this, 'AddForm', $this->getProfileFields('Add'), new FieldList( new FormAction('doAdd', _t('MemberProfiles.ADD', 'Add')) ), new MemberProfileValidator($this->Fields()) ); $this->extend('updateAddForm', $form); return $form; } /** * Saves an add member form submission into a new member object. */ public function doAdd($data, $form) { if($this->addMember($form)) $form->sessionMessage( _t('MemberProfiles.MEMBERADDED', 'The new member has been added.'), 'good' ); return $this->redirectBack(); } public function LoginLink() { return Controller::join_links( Injector::inst()->get('Security')->Link(), 'login', '?BackURL=' . urlencode($this->Link()) ); } /** * Gets the list of groups that can be set after the submission of a particular form * * This works around the problem with the checkboxsetfield which doesn't validate that the * groups that the user has selected are not validated against the list of groups the user is * allowed to choose from. * * @param Form $form * @param Member $member */ protected function getSettableGroupIdsFrom(Form $form, Member $member = null) { // first off check to see if groups were selected by the user. If so, we want // to remove that control from the form list (just in case someone's sent through an // ID for a group like, say, the admin's group...). It means we have to handle the setting // ourselves, but that's okay $groupField = $form->Fields()->dataFieldByName('Groups'); // The list of selectable groups $groupIds = $allowedIds = $this->SelectableGroups()->map('ID', 'ID')->toArray(); // we need to track the selected groups against the existing user's groups - this is // so that we don't accidentally remove them from the list of groups // a user might have been placed in via other means $existingIds = array(); if ($member) { $existing = $member->Groups(); if ($existing && $existing->Count() > 0) { $existingIds = $existing->map('ID', 'ID')->toArray(); // remove any that are in the selectable groups map - we only want to // worry about those that aren't managed by this form foreach ($groupIds as $gid) { unset($existingIds[$gid]); } } } if ($groupField) { $givenIds = $groupField->Value(); $groupIds = array(); if ($givenIds) { foreach ($givenIds as $givenId) { if (isset($allowedIds[$givenId])) { $groupIds[] = $givenId; } } } $form->Fields()->removeByName('Groups'); } foreach ($this->Groups()->column('ID') as $mustId) { $groupIds[] = $mustId; } foreach ($existingIds as $existingId) { if (!in_array($existingId, $groupIds)) { $groupIds[] = $existingId; } } return $groupIds; } /** * Allows the user to confirm their account by clicking on the validation link in * the confirmation email. * * @param HTTPRequest $request * @return array */ public function confirm($request) { if(Member::currentUser()) { return Security::permissionFailure ($this, _t ( 'MemberProfiles.CANNOTCONFIRMLOGGEDIN', 'You cannot confirm account while you are logged in.' )); } if ( $this->EmailType != 'Validation' || (!$id = $request->param('ID')) || (!$key = $request->getVar('key')) || !is_numeric($id) || !$member = DataObject::get_by_id('Member', $id) ) { $this->httpError(404); } if($member->ValidationKey != $key || !$member->NeedsValidation) { $this->httpError(403, 'You cannot validate this member.'); } $member->NeedsValidation = false; $member->ValidationKey = null; $member->write(); $this->extend('onConfirm', $member); $member->logIn(); return array ( 'Title' => $this->obj('ConfirmationTitle'), 'Content' => $this->obj('ConfirmationContent') ); } /** * Attempts to save either a registration or add member form submission * into a new member object, returning NULL on validation failure. * * @return Member|null */ protected function addMember($form) { $member = new Member(); $groupIds = $this->getSettableGroupIdsFrom($form); $form->saveInto($member); $member->ProfilePageID = $this->ID; $member->NeedsValidation = ($this->EmailType == 'Validation'); $member->NeedsApproval = $this->RequireApproval; try { $member->write(); } catch(ValidationException $e) { $form->sessionMessage($e->getResult()->message(), 'bad'); return; } // set after member is created otherwise the member object does not exist $member->Groups()->setByIDList($groupIds); // If we require admin approval, send an email to the admin and delay // sending an email to the member. if ($this->RequireApproval) { $groups = $this->ApprovalGroups(); $emails = array(); if ($groups) foreach ($groups as $group) { foreach ($group->Members() as $_member) { if ($member->Email) $emails[] = $_member->Email; } } if ($emails) { $email = new Email(); $config = SiteConfig::current_site_config(); $approve = Controller::join_links( Director::baseURL(), 'member-approval', $member->ID, '?token=' . $member->ValidationKey ); $email->setSubject("Registration Approval Requested for $config->Title"); $email->setBcc(implode(',', array_unique($emails))); $email->setTemplate('MemberRequiresApprovalEmail'); $email->populateTemplate(array( 'SiteConfig' => $config, 'Member' => $member, 'ApproveLink' => Director::absoluteURL($approve) )); $email->send(); } } elseif($this->EmailType != 'None') { $email = MemberConfirmationEmail::create($this, $member); $email->send(); } $this->extend('onAddMember', $member); return $member; } /** * @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()->map('ID', 'Title'); $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; } } |