function hook_user_role_delete

Respond to user role deletion.

This hook allows you act when a user role has been deleted. If your module stores references to roles, it's recommended that you implement this hook and delete existing instances of the deleted role in your module database tables.

Parameters

$role: The $role object being deleted.

Related topics

3 functions implement hook_user_role_delete()

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.

BlockHooks::userRoleDelete in core/modules/block/src/Hook/BlockHooks.php
Implements hook_ENTITY_TYPE_delete() for user_role entities.
block_user_role_delete in modules/block/block.module
Implements hook_user_role_delete().
UserHooks::userRoleDelete in core/modules/user/src/Hook/UserHooks.php
Implements hook_ENTITY_TYPE_delete() for user_role entities.
1 invocation of hook_user_role_delete()
user_role_delete in modules/user/user.module
Delete a user role from database.

File

modules/user/user.api.php, line 468

Code

function hook_user_role_delete($role) {
  // Delete existing instances of the deleted role.
  db_delete('my_module_table')->condition('rid', $role->rid)
    ->execute();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.