function hook_user_role_insert
Respond to creation of a new user role.
Modules implementing this hook can act on the user role object when saved to the database. It's recommended that you implement this hook if your module adds additional data to user roles object. The module should save its custom additions to the database.
Parameters
$role: A user role object.
Related topics
1 function implements hook_user_role_insert()
Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.
- UserHooks::userRoleInsert in core/
modules/ user/ src/ Hook/ UserHooks.php - Implements hook_ENTITY_TYPE_insert() for user_role entities.
1 invocation of hook_user_role_insert()
- user_role_save in modules/
user/ user.module - Save a user role to the database.
File
-
modules/
user/ user.api.php, line 426
Code
function hook_user_role_insert($role) {
// Save extra fields provided by the module to user roles.
db_insert('my_module_table')->fields(array(
'rid' => $role->rid,
'role_description' => $role->description,
))
->execute();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.