Have a requirement to develop drupal 9 custom module to get the mail id from the user registration form and store it separate table. I tried the hook_user_presave function to get the mail id but was not able to get it. Hereby sharing the code
function save_mail_user_presave(UserInterface $user) { try{ $conn = Database::getConnection(); $fields["mail"] = $user->get('mail')->value; $conn->insert('save_email') ->fields($fields)->execute(); Drupal::messenger()->addMessage($this->t(' Thank you !! Your> } catch(Exception $ex){ Drupal::logger('save_email')->error($ex->getMessage()); } }
Anybody helps me figure out the problem