Drupal 8 hook_user_insert() example

  1. function custom_module_user_insert($account) {
  2.  
  3. // Add new role to the user
  4. $account->addRole('test_role');
  5. // Block the user
  6. $account->block();
  7. // Save user
  8. $result = $account->save();
  9. drupal_get_messages();
  10.  
  11. // Redirect
  12. $config = \Drupal::config('fa_config_form.settings');
  13. $url = $config->get('registration_redirect');
  14. $response = new RedirectResponse($url);
  15. $response->send();
  16.  
  17. }