From 3b24bc27937993dac7e4138587597c09ce1c5d7c Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Sat, 14 May 2011 16:29:36 -0400 Subject: [PATCH] - Patch #1119158 by skwashd: Added user_role_save() doesn't implement a presave hook. --- modules/user/user.api.php | 19 +++++++++++++++++++ modules/user/user.module | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/modules/user/user.api.php b/modules/user/user.api.php index b674b12d4ea2..6adcf6d1ec17 100644 --- a/modules/user/user.api.php +++ b/modules/user/user.api.php @@ -366,6 +366,25 @@ function hook_user_view_alter(&$build) { $build['#post_render'][] = 'my_module_user_post_render'; } +/** + * Inform other modules that a user role is about to be saved. + * + * Modules implementing this hook can act on the user role object before + * it has been saved to the database. + * + * @param $role + * A user role object. + * + * @see hook_user_role_insert() + * @see hook_user_role_update() + */ +function hook_user_role_presave($role) { + // Set a UUID for the user role if it doesn't already exist + if (empty($role->uuid)) { + $role->uuid = uuid_uuid(); + } +} + /** * Inform other modules that a user role has been added. * diff --git a/modules/user/user.module b/modules/user/user.module index 40023d3d12b6..f5f42bd977b6 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -2828,6 +2828,10 @@ function user_role_save($role) { $query->addExpression('MAX(weight)'); $role->weight = $query->execute()->fetchField() + 1; } + + // Let modules modify the user role before it is saved to the database. + module_invoke_all('user_role_presave', $role); + if (!empty($role->rid) && $role->name) { $status = drupal_write_record('role', $role, 'rid'); module_invoke_all('user_role_update', $role); -- GitLab