User not activated when using RegisterFormBuilder in Multiple Form

kiltedup - 1 week ago

Hi, I have created a MultipleFormBuilder that uses the RegisterFormBuilder alongside a couple of other custom forms. Everything works with the exception of the User being activated once created. Activation mode is set to Automatic, and if I use the RegisterFormBuilder standalone, then the created user is activated. Is there anything that needs to be added to the Multiple form to activate the user? Cheers, Dave

kiltedup - 1 week ago

Just tried that.

No - when the RegisterFormBuilder is used in a MultipleForm it does not get hit.

Checked again with the Register form standalone and the dd got hit.

ryanthompson - 1 week ago

Interesting.. I feel like the handler should still get hit..

ryanthompson - 1 week ago

@kiltedup I feel like this might be a design bug - spin up an issue for child forms not handling - and I'll look into the safety of correcting it.

By default the handler simply does if can save $form->save() so I think it will be but.. Issue that up and I'll address it today.

kiltedup - 1 week ago

May have misread this but are you saying the Handler of the form that is added does not get hit, but a different child form handler is used - with the $form->save()

The form is saved its just that its not activated and login doesn't happen - that would make sense I guess if it's a child form handler that is run - no authenticator or activator.

I've worked around it by throwing the activator and authenticator on into my on('save_user')

ryanthompson - 1 week ago

Ya that's a perfect workaround - but I was saying that the handler SHOULD be run I think from multi's for this very reason. So I will patch that later today after looking at the potential side effects more thoroughly. assume tomorrow you won't have to work around it.

ryanthompson - 1 week ago

So after some research the handler SHOULD be being hit. Cause it's post() method is being ran which runs the handlers. I tested to confirm as well.

So my assumption is that you have extended the RegisterFormBuilder with your own and something to keep in mind is that:

automatically detected component handlers will not work if the class is overridden

This is because by binding your own - you essentially change the location of the class and the handlers are no longer next to it and can not be detected. So for the handler - you would need to set that property on your class explicitly.

protected $handler = RegisterFormHandler::class;

Give that a shot I think you'll find it's all working as expected.

kiltedup - 1 week ago

Hey - sorry. Got sidetracked and been away.

Thanks for looking into this. I'm stumped. Haven't extended the RegisterFormBuilder - simply using it as it is.

This is my test code : all works - user is created along side the other two form entries (my own stuff). Just not getting the new user activated or logged in - with the dd you suggested not being hit ???

SignupFormBuilder is a MultipleForm.

use Anomaly\UsersModule\User\Register\RegisterFormBuilder;

public function signup(
    SignupFormBuilder $form, 
    RegisterFormBuilder $userForm, 
    ProfileFormBuilder $profileForm, 
    AccountFormBuilder $accountForm
){
    $form->addForm('user', $userForm);

    $profileForm->setSkips(['user']);
    $form->addForm('profile', $profileForm);

    $accountForm->setSkips(['user','plan']);
    $form->addForm('account', $accountForm);

    $form->on('saved_user', function() use ($form) {

        $user = $form->getChildFormEntry('user');

        $profile = $form->getChildFormEntry('profile');
        $profile->user = $user;

        $account = $form->getChildFormEntry('account');
        $account->user = $user;
    });

    return $form->render();
}