| 7 user.api.php | hook_user_insert(& |
| 8 user.api.php | hook_user_insert($account) |
A user account was created.
The module should save its custom additions to the user object into the database.
Parameters
$edit: The array of form values submitted by the user.
$account: The user object on which the operation is being performed.
$category: The active category of user information being edited.
See also
Related topics
4 functions implement hook_user_insert()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- entity_crud_hook_test_user_insert in modules/
simpletest/ tests/ entity_crud_hook_test.module - Implements hook_user_insert().
- openid_user_insert in modules/
openid/ openid.module - Implements hook_user_insert().
- profile_user_insert in modules/
profile/ profile.module - Implements hook_user_insert().
- trigger_user_insert in modules/
trigger/ trigger.module - Implements hook_user_insert().
2 invocations of hook_user_insert()
- field_attach_insert in modules/
field/ field.attach.inc - Save field data for a new entity.
- user_save in modules/
user/ user.module - Save changes to a user account or add a new user.
File
- modules/
user/ user.api.php, line 252 - Hooks provided by the User module.
Code
function hook_user_insert(&$edit, $account, $category) {
db_insert('mytable')->fields(array(
'myfield' => $edit['myfield'],
'uid' => $account->uid,
))->execute();
}
Comments
Can this be used to emulate 'access rules' in Drupal 7?
PermalinkIs there an easier way to, for example, block all users that do not have email addresses from a certain institution?
Edit: Found the Rules module does it. Sorry for the spam, folks.
RULES :D omg, great idea ;)
PermalinkRULES :D omg, great idea ;) thx
User Restrictions
PermalinkAlso the User Restrictions module
question on 'user' vs 'account'
PermalinkI'm relatively clueless about php but trying to add a subscription for all new users, and finding a problem: if admin adds a user, then the $account value is admin. Is it possible to grab or construct the new user object from the $edit object? Does it exist at this point?
Documentation for $edit is a bit misleading
PermalinkThe documentation here is a bit misleading. The $edit object is not just the array of form values, but rather the array of form values after stripping any which don't match up to the account object.
So, you can't add extra values to the $form_state array and expect them to be in this $edit object. Only items which match up to the fields in the user object are passed, all others are stripped out.