2

I am new to Drupal. I want to execute my custom function every time when user registers or logins to my site. How can I do this?

3

You can do this using the following hooks in your module.

  1. hook_user_login
  2. hook_user_register (In D7 we had user_insert hook.)

Examples:

User Login Hook:

function mymodule_user_login($account){

   //your code here
}

User Register Hook:

function mymodule_user_insert(Drupal\Core\Entity\EntityInterface $entity){

   //your code here

}
| improve this answer | |
  • Thanq @esafwan . Where i need to place this code. In theme file or what ? – MH9 Jun 14 '17 at 8:44
  • @Mithun You have put this in a module. What does the custom function do? You might be able to use rules module instead for some use cases. – esafwan Jun 14 '17 at 15:31
  • 2
    How can i get form values like first name, last name, email and password in mymodule_user_insert – MH9 Jun 19 '17 at 10:00
0

You can also use rule module for user login/register.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.