Is it possible to replace an object of the UserLoginForm class with one of my own class?
What I want to do is replacing the login form with a custom one which would ask users to enter a code sent to their email address, once they entered the correct user credentials.
The problem is that an object of that class is created from UserController::userPage().
if ($user->id()) {
$response = new RedirectResponse(url('user/' . $user->id(), array('absolute' => TRUE)));
}
else {
$response = drupal_get_form(UserLoginForm::create($this->container), $request);
}
I know I can implement hook_form_alter() to alter the form, but I would like to use a class like UserLogin
, and replacing $form_state['build_info']['callback_object']
with the object of my class in hook_form_alter()
is probably too late.
Is it possible to use a class for altering the user login form? How?