Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There are two problems I have with the current implementation of the user update service:
- Since it's directly modeled after the user profile form, it can take multiple update calls to affect change on a single user. I don't really like the way core does this either. (Hopefully it's been remedied in later Drupal versions. Admittedly, I haven't looked beyond 6.)
- You always have to pass values for every field that would appear on the form, even though you may only want to update the value of a single field, otherwise existing values will get wiped out and required fields will give you validation errors.
Both of these make it pretty difficult for an outside entity to make use of the service.
My ultimate wish is that you could affect change on just the fields you send to the service, leaving any existing values as-is, and using only one call, no matter what category the fields might fall under.
Comment | File | Size | Author |
---|---|---|---|
#1 | refactor-user-update-1910012-1.patch | 5.03 KB | kevin.dutra |
Comments
Comment #1
kevin.dutra CreditAttribution: kevin.dutra commentedHere's a patch that basically does what I want it to. It's not perfect, but hopefully it will at least serve to start some discussion.
The basic idea is that edits submitted to the service are merged with the existing user object values. This should prevent the issue with data being wiped out or with required fields complaining because you didn't submit a value. (True, there'll still be the case where a field has just become required and you're editing a user that doesn't have a value there yet. That seems fine to me.)
Then the every profile form is submitted so that it only takes one call to the service.
Comment #2
kylebrowning CreditAttribution: kylebrowning commentedComment #3
marcingy CreditAttribution: marcingy commentedAll these changes need to go into D7 first and then be backported
This hunk worries me as it has a db query why not call profile_categories() instead - yes it does pretty much the same but leaves us with less code to maintain.
so effectively we become
Another strange thing is
Can we not just assign.
Comment #4
kevin.dutra CreditAttribution: kevin.dutra commentedThat's definitely an option. Note that
profile_categories()
gives you an array of arraysso it wouldn't be quite as simple as
Yep, I believe you're correct. $form_state should be an array, not an object, so it shouldn't require cloning. Not sure why I did that...
Comment #5
kylebrowning CreditAttribution: kylebrowning commentedIs this still wanted? Patch doesn't apply.