summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/user/user.api.php19
-rw-r--r--modules/user/user.module4
2 files changed, 23 insertions, 0 deletions
diff --git a/modules/user/user.api.php b/modules/user/user.api.php
index b674b12d4..6adcf6d1e 100644
--- a/modules/user/user.api.php
+++ b/modules/user/user.api.php
@@ -367,6 +367,25 @@ function hook_user_view_alter(&$build) {
}
/**
+ * 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.
*
* Modules implementing this hook can act on the user role object when saved to
diff --git a/modules/user/user.module b/modules/user/user.module
index 92a55bcf4..204155a4c 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);