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?
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
}