Skip to content

Instantly share code, notes, and snippets.

@cotto
Created September 29, 2011 21:27
Show Gist options
  • Save cotto/1251990 to your computer and use it in GitHub Desktop.
Save cotto/1251990 to your computer and use it in GitHub Desktop.
diff --git a/resources/user_resource.inc b/resources/user_resource.inc
index e84eb3d..c8a0fb2 100644
--- a/resources/user_resource.inc
+++ b/resources/user_resource.inc
@@ -282,9 +282,11 @@ function _user_resource_update($uid, $account) {
// If a profile category was passed in, use it. Otherwise default
// to 'account' (for saving core user data.)
$category = 'account';
+ $has_category = 0;
if (isset($account['category'])) {
$category = $account['category'];
unset($account['category']);
+ $has_category = 1;
}
// Drop any passed in values into the $account var. Anything
@@ -303,11 +305,25 @@ function _user_resource_update($uid, $account) {
);
}
- $ret = drupal_execute('user_profile_form', $form_state, $user, $category);
-
- // Error if needed.
- if ($errors = form_get_errors()) {
- return services_error(implode(" ", $errors), 406, array('form_errors' => $errors));
+ // If no category was specified, update all categories.
+ if (!$has_category) {
+ // Only variables can be passed by reference workaround.
+ $null = NULL;
+ foreach (module_implements('user') as $module) {
+ $hook_user_impl = $module .'_user';
+ // $null and $account need to be passed by reference.
+ if (function_exists($hook_user_impl) && ($data = $hook_user_impl('categories', $null, $account, ''))) {
+ foreach ($data as $d) {
+ $category_list[] = $d['name'];
+ }
+ }
+ }
+ foreach($category_list as $category_name) {
+ _services_submit_user_data($user, $form_state, $category_name);
+ }
+ }
+ else {
+ _services_submit_user_data($user, $form_state, $category);
}
services_remove_user_data($account);
@@ -316,6 +332,21 @@ function _user_resource_update($uid, $account) {
}
/**
+ * submit user profile data for a single category
+ */
+
+function _services_submit_user_data($user, $form_state, $category) {
+ $ret = drupal_execute('user_profile_form', $form_state, $user, $category);
+
+ // Error if needed.
+ if ($errors = form_get_errors()) {
+ services_error(implode(" ", $errors), 406, array('form_errors' => $errors));
+ }
+ return $ret;
+}
+
+
+/**
* Delete a user.
*
* @param $uid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment