src/Pages/MemberProfilePageController.php
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) {
            $validationMessages = implode("; ", $e->getResult()->getMessages());
            $form->sessionMessage($validationMessages, 'bad');
            return null;
        }

        // 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();
            if (!$groups ||
                $groups->count() == 0) {
                // If nothing is configured, fallback to ADMIN
                $groups = Permission::get_groups_by_permission('ADMIN');
            }

            $emails = [];
            if ($groups) {
                foreach ($groups as $group) {
                    foreach ($group->Members() as $_member) {
                        if ($_member->Email) {
                            $emails[] = $_member->Email;
                        }
                    }
                }
            }

            if ($emails) {
                $emails = array_unique($emails);

                $mail   = Email::create();
                $config  = SiteConfig::current_site_config();
                $approve = Controller::join_links(
                    Director::baseURL(),
                    'member-approval',
                    $member->ID,
                    '?token=' . $member->ValidationKey
                );

                $mail->setSubject("Registration Approval Requested for $config->Title");
                foreach ($emails as $email) {
                    if (!Email::is_valid_address($email)) {
                        // Ignore invalid email addresses or else we'll get validation errors.
                        // ie. default 'admin' account
                        continue;
                    }
                    $mail->addBCC($email);
                }
                $mail->setHTMLTemplate('Symbiote\\MemberProfiles\\Email\\MemberRequiresApprovalEmail');
                $mail->setData(array(
                    'SiteConfig'  => $config,
                    'Member'      => $member,
                    'ApproveLink' => Director::absoluteURL($approve)
                ));

                $mail->send();
            }
        } else {
            // NOTE(Jake): 2018-05-03
            //
            // Only send the confirmation email immediately after registering if they
            // don't require admin approval.
            //
            switch ($this->EmailType) {
                case 'None':
                    // Does not require anything
                break;

                case 'Confirmation':
                case 'Validation':
                    // Must activate themselves via the confirmation email
                    $email = MemberConfirmationEmail::create($this->data(), $member);
                    $email->send();
                break;
            }
        }

        $this->extend('onAddMember', $member);
        return $member;
    }
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) {
            $validationMessages = implode("; ", $e->getResult()->getMessages());
            $form->sessionMessage($validationMessages, 'bad');
            return null;
        }

        // 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();
            if (!$groups ||
                $groups->count() == 0) {
                // If nothing is configured, fallback to ADMIN
                $groups = Permission::get_groups_by_permission('ADMIN');
            }

            $emails = [];
            if ($groups) {
                foreach ($groups as $group) {
                    foreach ($group->Members() as $_member) {
                        if ($_member->Email) {
                            $emails[] = $_member->Email;
                        }
                    }
                }
            }

            if ($emails) {
                $emails = array_unique($emails);

                $mail   = Email::create();
                $config  = SiteConfig::current_site_config();
                $approve = Controller::join_links(
                    Director::baseURL(),
                    'member-approval',
                    $member->ID,
                    '?token=' . $member->ValidationKey
                );

                $mail->setSubject("Registration Approval Requested for $config->Title");
                foreach ($emails as $email) {
                    if (!Email::is_valid_address($email)) {
                        // Ignore invalid email addresses or else we'll get validation errors.
                        // ie. default 'admin' account
                        continue;
                    }
                    $mail->addBCC($email);
                }
                $mail->setHTMLTemplate('Symbiote\\MemberProfiles\\Email\\MemberRequiresApprovalEmail');
                $mail->setData(array(
                    'SiteConfig'  => $config,
                    'Member'      => $member,
                    'ApproveLink' => Director::absoluteURL($approve)
                ));

                $mail->send();
            }
        } else {
            // NOTE(Jake): 2018-05-03
            //
            // Only send the confirmation email immediately after registering if they
            // don't require admin approval.
            //
            switch ($this->EmailType) {
                case 'None':
                    // Does not require anything
                break;

                case 'Confirmation':
                case 'Validation':
                    // Must activate themselves via the confirmation email
                    $email = MemberConfirmationEmail::create($this->data(), $member);
                    $email->send();
                break;
            }
        }

        $this->extend('onAddMember', $member);
        return $member;
    }
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 ) { $ validationMessages = implode ( "; " , $ e -> getResult ( ) -> getMessages ( ) ) ; $ form -> sessionMessage ( $ validationMessages , 'bad' ) ; return null ; } // 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 ( ) ; if ( ! $ groups || $ groups -> count ( ) == 0 ) { // If nothing is configured, fallback to ADMIN $ groups = Permission :: get_groups_by_permission ( 'ADMIN' ) ; } $ emails = [ ] ; if ( $ groups ) { foreach ( $ groups as $ group ) { foreach ( $ group -> Members ( ) as $ _member ) { if ( $ _member -> Email ) { $ emails [ ] = $ _member -> Email ; } } } } if ( $ emails ) { $ emails = array_unique ( $ emails ) ; $ mail = Email :: create ( ) ; $ config = SiteConfig :: current_site_config ( ) ; $ approve = Controller :: join_links ( Director :: baseURL ( ) , 'member-approval' , $ member -> ID , '?token=' . $ member -> ValidationKey ) ; $ mail -> setSubject ( "Registration Approval Requested for $config->Title" ) ; foreach ( $ emails as $ email ) { if ( ! Email :: is_valid_address ( $ email ) ) { // Ignore invalid email addresses or else we'll get validation errors. // ie. default 'admin' account continue ; } $ mail -> addBCC ( $ email ) ; } $ mail -> setHTMLTemplate ( 'Symbiote\\MemberProfiles\\Email\\MemberRequiresApprovalEmail' ) ; $ mail -> setData ( array ( 'SiteConfig' => $ config , 'Member' => $ member , 'ApproveLink' => Director :: absoluteURL ( $ approve ) ) ) ; $ mail -> send ( ) ; } } else { // NOTE(Jake): 2018-05-03 // // Only send the confirmation email immediately after registering if they // don't require admin approval. // switch ( $ this -> EmailType ) { case 'None' : // Does not require anything break ; case 'Confirmation' : case 'Validation' : // Must activate themselves via the confirmation email $ email = MemberConfirmationEmail :: create ( $ this -> data ( ) , $ member ) ; $ email -> send ( ) ; break ; } } $ this -> extend ( 'onAddMember' , $ member ) ; return $ member ; }
Attempts to save either a registration or add member form submission
into a new member object, returning NULL on validation failure.

@return Member|null
Attempts to save either a registration or add member form submission into a new member object returning NULL on validation failure .