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?
2 Answers
You can do this using the following hooks in your module.
- hook_user_login
- 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
}
-
Thanq @esafwan . Where i need to place this code. In theme file or what ?– MH9Jun 14, 2017 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.– esafwanJun 14, 2017 at 15:31
-
2How can i get form values like first name, last name, email and password in mymodule_user_insert– MH9Jun 19, 2017 at 10:00