The patches does the following things:

- Adding apidocs for all hook_user_* hooks.
- Remove unecessary & from $user and $account
- Remove unecessary arguments (for example, change hook_user_view(&$edit = NULL, $account, $category = NULL) to hook_user_view($account), remove $category from login/logout hook and so on.)
- Remove hook_profile_alter hook. there is simply no need for that, as it is doing exactly the same as hook_user_view($account).

CommentFileSizeAuthor
#42 drupal.user-admin-forms.42.patch13.63 KBsun
FAILED: [[SimpleTest]]: [MySQL] 23,291 pass(es), 2 fail(s), and 0 exception(es). View
#39 drupal.user-admin-forms.39.patch13.23 KBsun
FAILED: [[SimpleTest]]: [MySQL] 18,727 pass(es), 2 fail(s), and 0 exception(es). View
#35 more_user_cleanup_no_post4.patch12.91 KBBerdir
Failed: 12736 passes, 2 fails, 0 exceptions View
#30 more_user_cleanup_no_post3.patch16.35 KBBerdir
Failed: Failed to apply patch. View
#25 more_user_cleanup_no_post2.patch16.21 KBBerdir
Failed: 11418 passes, 3 fails, 0 exceptions View
#22 more_user_cleanup2.patch7.11 KBBerdir
Failed: 12114 passes, 1 fail, 2 exceptions View
#22 more_user_cleanup_no_post.patch10.33 KBBerdir
Failed: 12079 passes, 2 fails, 0 exceptions View
#19 more_user_cleanup.patch6.42 KBBerdir
Failed: 12007 passes, 90 fails, 2 exceptions View
#16 user_hook_fixes6.patch32.58 KBBerdir
Failed: Failed to apply patch. View
#10 user_hook_fixes5.patch25.98 KBBerdir
Failed: Failed to apply patch. View
#8 user_hook_fixes4.patch25.99 KBBerdir
Failed: Failed to apply patch. View
#6 user_hook_fixes3.patch25.95 KBBerdir
Failed: Failed to apply patch. View
#2 user_hook_fixes2.patch25.41 KBBerdir
Failed: Failed to apply patch. View
user_hook_fixes.patch25.4 KBBerdir
Failed: Failed to apply patch. View
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
25.41 KB
Failed: Failed to apply patch. View

Re-roll.

Status: Needs review » Needs work

The last submitted patch failed testing.

lilou’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
25.95 KB
Failed: Failed to apply patch. View

Re-roll, there was a conflict in system.api.php

Status: Needs review » Needs work

The last submitted patch failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
25.99 KB
Failed: Failed to apply patch. View

Another re-roll...

Status: Needs review » Needs work

The last submitted patch failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
25.98 KB
Failed: Failed to apply patch. View

D'oh, another conflict in system.api.php.. nobody wants to review this ? :)

Status: Needs review » Needs work

The last submitted patch failed testing.

deekayen’s picture

Status: Needs work » Needs review

core was broken

Berdir’s picture

Title: Fix and document hook_user_*() » Fix horrifying mess of crap in user module hooks

New title, suggested by webchick!

webchick’s picture

+++ modules/blog/blog.module	13 Jul 2009 11:47:37 -0000
@@ -44,7 +44,7 @@ function blog_access($op, $node, $accoun
-function blog_user_view(&$edit, &$user, $category) {
+function blog_user_view($user) {

Since we're cleaning things up anyway, let's rename $user to $account in all hook implementations for consistency.

+++ modules/profile/profile.module	13 Jul 2009 11:47:41 -0000
@@ -205,49 +205,49 @@ function profile_block_view($delta = '')
  * Implement hook_user_form().
+++ modules/user/user.api.php	13 Jul 2009 11:47:53 -0000
@@ -263,6 +211,181 @@ function hook_user_categories() {
+function hook_user_register(&$edit, $account, $category) {
+  if (variable_get('configurable_timezones', 1)) {

Out of scope for this issue certainly, but since you had your head this deep into user module, do we still need these hooks? Isn't hook_form_alter() just as good, or no?

+++ modules/system/system.api.php	13 Jul 2009 11:47:45 -0000
@@ -566,19 +566,6 @@ function hook_link_alter(array &$links, 
-function hook_profile_alter(&$account) {
-  foreach ($account->content AS $key => $field) {
-    // do something
-  }
-}

I'm not sure about removing this hook.

This was added back in #74395: hook_profile_alter() - let modules alter the profile page, and $account was passed by reference even in the dark days of Drupal 5. Unfortunately, there's not much there in the way of community discussion around why the change was necessary.

However, the overall pattern of "build up something by querying all modules that want to add primary content, then allow modules to alter the entirety of the primary content" seems pervasive wherever I search for a call to drupal_alter(). So IMO, let's leave it in, with an eye towards removing it in D8 if it really is unnecessary.

Alternately, get Moshe to chime in here and see what he has to say.

+++ modules/user/user.api.php	13 Jul 2009 11:47:53 -0000
@@ -12,79 +12,6 @@
-function hook_user($op, &$edit, &$account, $category = NULL) {

(and 1200 other - lines)

This makes me so happy I could squeal like a little girl. ;)

+++ modules/user/user.api.php	13 Jul 2009 11:47:53 -0000
@@ -251,9 +178,30 @@ function hook_user_operations() {
+function hook_user_after_update(&$edit, $account, $category) {
@@ -263,6 +211,181 @@ function hook_user_categories() {
+function hook_user_logout($account) {
...
+function hook_user_submit(&$edit, $account, $category) {
...
+function hook_user_validate(&$edit, $account, $category) {
...
+function hook_user_view($account) {

Is there any way I can convince you to add examples for these hooks? I'm not confident that if they don't get added now that they ever will be.

+++ modules/user/user.api.php	13 Jul 2009 11:47:53 -0000
@@ -263,6 +211,181 @@ function hook_user_categories() {
+ * The user account is being added.
...
+ * The user account is being changed.

Let's keep past-tense like elsewhere: the user account was just added/changed.

+++ modules/user/user.module	13 Jul 2009 11:47:57 -0000
@@ -23,7 +23,7 @@ define('EMAIL_MAX_LENGTH', 64);
+function user_module_invoke($type, &$array, $user, $category = NULL) {

Can we rename $array as $edit now?

20 days to code freeze. Better review yourself.

webchick’s picture

Status: Needs review » Needs work
Berdir’s picture

Status: Needs work » Needs review
FileSize
32.58 KB
Failed: Failed to apply patch. View

Since we're cleaning things up anyway, let's rename $user to $account in all hook implementations for consistency.

Done.

Out of scope for this issue certainly, but since you had your head this deep into user module, do we still need these hooks? Isn't hook_form_alter() just as good, or no?

Not sure, hook_form_alter is probably enough but as you said, nothing for this issue.

This was added back in #74395: hook_profile_alter() - let modules alter the profile page, and $account was passed by reference even in the dark days of Drupal 5. Unfortunately, there's not much there in the way of community discussion around why the change was necessary.

As I said in IRC, the view hook worked differently back in D5: http://api.drupal.org/api/function/user_view/5. New stuff was returned so it was not possible to change things added by other modules, but this is not true anymore. The hook was probably already unecessary in D6, but was not removed. I will pink moshe about this, to be certain.

Is there any way I can convince you to add examples for these hooks? I'm not confident that if they don't get added now that they ever will be.

I added *something*, it does not make much sense, but it's better than nothing I guess...

Let's keep past-tense like elsewhere: the user account was just added/changed.

As discussed, insert/update is called before the account was added/changed, but I changed it in a few other instances...


Can we rename $array as $edit now?

Done.

I discussed this with webchick in #drupal and we found lots and lots of funny things in user.module and profile.module and others.. I fixed some of them in the patch and leaving others for follow-ups or this will never be finished.

Other changes in this patch:
- removed contact_user_validate.. that does just return an array since Drupal 4.6, however the validate hook does not expect an return value :) More "-" lines, yay!
- There is still hook_user_register(&$edit, $account = NULL, $category = NULL), but that goes through _user_forms() and is more complicated to simplify.
- Renamed profile_view_profile to profile_user_view and profile_validate_profile to profile_user_validate, as the current hooks just passed through the arguments. the other hooks handle $register = TRUE/FALSE so I didn't change them.

Follow-Up Stuff:
- user_edit/user_profile_form/user_edit_form is quite a mess, there are submit/validate functions for functions that aren't form functions and other nice stuff.

Dries’s picture

Status: Needs review » Needs work

Committed to CVS HEAD. Great job, Berdir.

I'm marking this 'code needs work' so we can follow up on the user_edit/user_profile_form/user_edit_form stuff and other tidbits.

webchick’s picture

Issue tags: +Needs Documentation

Also, let's document this sucker.

Berdir’s picture

Status: Needs work » Needs review
Issue tags: -Needs Documentation
FileSize
6.42 KB
Failed: 12007 passes, 90 fails, 2 exceptions View

Added http://drupal.org/update/modules/6/7#hook-user-changes.

This removes the mentioned user_edit_* code that is not used. It also simpliefies user_admin() a bit, by moving create out of it.

moshe weitzman’s picture

very nice work here ... can we please please get rid of the switch on $_POST. Thats pre-fapi code right there.

Status: Needs review » Needs work

The last submitted patch failed testing.

Berdir’s picture

FileSize
10.33 KB
Failed: 12079 passes, 2 fails, 0 exceptions View
7.11 KB
Failed: 12114 passes, 1 fail, 2 exceptions View

@moshe

I tried, but I can't get the cancel stuff working. Attached is the patch that does convert that part to be similiar to the node_admin_content stuff. However, node multiple delete doesn't work for me either, so I'm not sure what is wrong exactly.

The test fails were because I forgot to update the category menu entries.

Berdir’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

Berdir’s picture

FileSize
16.21 KB
Failed: 11418 passes, 3 fails, 0 exceptions View

This should work now, without $_POST. Not sure what I changed, though.... I moved the multiple_cancel form functions to user.admin.inc and then it worked...

Berdir’s picture

Status: Needs work » Needs review
moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Lovely. Many thanks.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

This is a great little clean-up! :D

+++ modules/user/user.admin.inc	13 Aug 2009 11:26:50 -0000
@@ -6,24 +6,20 @@
+/**
+ * Form builder; Return user administration forms.
+ *
+ * @ingroup forms
+ */

Convention is to @see document the validation/submit functions associated with a form.

+++ modules/user/user.admin.inc	13 Aug 2009 11:26:50 -0000
@@ -6,24 +6,20 @@
+function user_admin(&$form_state) {

While we're at it, can we make this "user_admin_form" to make it more explicit what it is at a glance?

+++ modules/user/user.admin.inc	13 Aug 2009 11:26:50 -0000
@@ -42,6 +38,7 @@ function user_filter_form() {
+  $form['#submit'][] = 'user_filter_form_submit';
@@ -153,6 +147,8 @@ function user_admin_account() {
+  $form['#theme'] = 'user_admin_account';
@@ -171,6 +167,8 @@ function user_admin_account() {
+    '#submit' => array('user_admin_account_submit'),
+    '#validate' => array('user_admin_account_validate'),

Why is this necessary? Doesn't the submit function fire automatically based on naming convention of $form_id?

+++ modules/user/user.admin.inc	13 Aug 2009 11:26:50 -0000
@@ -973,3 +975,77 @@ function user_modules_uninstalled($modul
+function user_multiple_cancel_confirm(&$form_state) {

PHPDoc please.

Also see note about @see.

18 days to code freeze. Better review yourself.

Berdir’s picture

Convention is to @see document the validation/submit functions associated with a form.

Hm.. the thing is, there are no submit/validate functions for user_admin_form. It just calls other form functions and they have validate/submit functions. Not sure if I should add all of them as that would be quite a list ;)

Why is this necessary? Doesn't the submit function fire automatically based on naming convention of $form_id?

As above, $form_id is user_admin_form. That doesn't match.

Working on a re-roll...

Berdir’s picture

Status: Needs work » Needs review
FileSize
16.35 KB
Failed: Failed to apply patch. View

Ok, re-rolled without @see for all submit/validate functions, they aren't listed on http://api.drupal.org/api/function/node_admin_content/7 either.

axyjo’s picture

Fixed a recurring spelling error in http://drupal.org/update/modules/6/7#hook-user-changes (unecessary to unnecessary).

Edit: however, I don't have permissions to fix this in http://drupal.org/node/394070. Anyone who does have permissions is welcome to fix it.

yched’s picture

@Berdir: Could you take a look at #549726: user_profile_form_validate() not called when submitting user_profile_form ? Maybe related to the recent changes, maybe not, but your work here definitely makes you one of the carbon-based organisms most intimate with the current state of user.module ;-)

Status: Needs review » Needs work

The last submitted patch failed testing.

Berdir’s picture

Assigned: Berdir » Unassigned

Can someone re-roll this? I don't have time until code freeze I think...

Berdir’s picture

Status: Needs work » Needs review
FileSize
12.91 KB
Failed: 12736 passes, 2 fails, 0 exceptions View

Here is a try.

Re-added the user_edit() helper function to make DamZ happy, as he didn't liked drupal_set_message() in a form callback though I can't really understand why that is bad :)

Untested.

Status: Needs review » Needs work

The last submitted patch failed testing.

sun’s picture

This patch would be really nice to still get in. AFAICS, it doesn't break any public API function of User module. But we don't want to waste time in re-rolling if it doesn't have a chance, so please let us know.

RobLoach’s picture

I absolutely love the issue title here. Hitting the subscribe button.

sun’s picture

Status: Needs work » Needs review
FileSize
13.23 KB
FAILED: [[SimpleTest]]: [MySQL] 18,727 pass(es), 2 fail(s), and 0 exception(es). View

Re-rolled against HEAD.

Status: Needs review » Needs work

The last submitted patch, drupal.user-admin-forms.39.patch, failed testing.

reglogge’s picture

Might this be related to the "horrifying mess of crap" thing?

#892950: (Tests needed) No welcome mail sent to new users after site administrator approval

sun’s picture

Assigned: Unassigned » sun
Status: Needs work » Needs review
FileSize
13.63 KB
FAILED: [[SimpleTest]]: [MySQL] 23,291 pass(es), 2 fail(s), and 0 exception(es). View

Possible, but not entirely sure.

Re-rolled against HEAD.

Status: Needs review » Needs work

The last submitted patch, drupal.user-admin-forms.42.patch, failed testing.

sun’s picture

Version: 7.x-dev » 8.x-dev
Assigned: sun » Unassigned

Although badly needed, this is D8 material according to the rules (I had to learn today). It may be backported at a later point in time (though that's unlikely).

mgifford’s picture

Issue summary: View changes

Is this still needed?

sun’s picture

Status: Needs work » Fixed

It looks like most of the legacy code has been cleaned up when the forms were moved into classes already.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.