Drupal-8-user-register-hook Apr 2026
use Drupal\user\UserInterface; /** * Implements hook_ENTITY_TYPE_presave() for user entities. */ function my_module_user_presave(UserInterface $user) { // Check if this is a new user registration if ($user->isNew()) { // Perform custom logic, e.g., set a field value $user->set('field_welcome_status', 'Pending'); } } Use code with caution. Copied to clipboard 🎯 Key Considerations
For cleaner, decoupled code, consider Symfony Event Subscribers if you are using the Hook Event Dispatcher module. drupal-8-user-register-hook
The most effective way to intercept or modify user data during registration is through the following hooks: Usage Note Runs before the user is saved. The most effective way to intercept or modify
Use this to add custom fields or validation logic (e.g., matching a secondary database). 💻 Code Example: hook_user_presave Runs after the user is created
[Solved] How to hook into Commerce after payment complete - Drupal
Best for modifying data (e.g., adding a default role) before it hits the database. Runs after the user is created.