Download & Extend

Remove $op from hook_user: Documentation

Project:Drupal core
Version:7.x-dev
Component:user.module
Category:bug report
Priority:critical
Assigned:beejeebus
Status:closed (fixed)

Issue Summary

first cut, this is just rearranging mostly.

motivation comes from lots of places, good discussion on the dev list here.

all tests pass. (as an aside, huge thanks to all who've worked on simpletest, definitely saved me a bunch of time when creating this patch.)

still needs heaps of code docs, and another cut to take advantage of the fact that we don't have to use the one-size-fits-all API. might be a separate issue or two though.

AttachmentSizeStatusTest resultOperations
hook_user.patch23.23 KBIdleFailed: Failed to apply patch.View details

Comments

#1

added some phpdoc for new functions.

took out the

<?php
if ($hook == 'user')
?>
hack in module.inc (thanks chx).

all tests pass except for 3 in 'Upload user picture', which are failing on a clean HEAD for me at the moment.

any opinions on whether this will make it into D7?

AttachmentSizeStatusTest resultOperations
user.patch25.69 KBIdleFailed: Failed to apply patch.View details

#2

Category:feature request» bug report
Priority:normal» critical

We shouldn't release D7 with any $ops left in it IMO.

A few things I noticed -

statistics.module is missing phpdoc for Implementation of...
trigger.module has // Nasty hack... - surely // @TODO?
We should be passing $user as an object to all of these hooks, and probably using module_invoke_all for them too, but that could be a followup patch.
I looks like we should remove hook_user_form and just use hook_form_alter() instead unless I'm missing something - again - fine with that being a followup patch.

#3

@catch: thanks for quick review. i like the idea of passing in $user, but the intention of this patch is to just remove $op, then we can make the api better with follow up patches. trying to do as webchick suggests with simple patches...

added phpdoc for statistics.module.

added TODO for trigger.module.

AttachmentSizeStatusTest resultOperations
user.patch25.8 KBIdleFailed: Failed to apply patch.View details

#4

will update this patch once HEAD is fixed.

#5

updated for HEAD, all tests pass.

AttachmentSizeStatusTest resultOperations
user.patch25.79 KBIdleFailed: Failed to apply patch.View details

#6

Status:needs review» reviewed & tested by the community

So there's plenty of followup work to do once this gets in - like use module_invoke_all instead of user_module_invoke, pass it a user object, get rid of the fapi stuff etc. etc. - but that can all be done in subsequent patches. I confirmed that all tests pass, so marking RTBC.

#7

Status:reviewed & tested by the community» needs work

Committed to CVS HEAD.

I'm marking this code needs work until the upgrade docs have been updated.

Thanks! Awesome patch.

#8

Status:needs work» fixed

Added the update module documentation for remove $op.

#9

Status:fixed» closed (fixed)

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

#10

Status:closed (fixed)» needs work

api docs haven't been updated yet: http://api.drupal.org/api/function/hook_user/7

#11

On a rather unrelated topic of docs, #314870: UNSTABLE-4 blocker: Add api.php for every core module would really be nice....

#12

Just noticed this still needs docs (now in user.api.php).

#13

this patch rewrites the user.api.php to a removed op

TODO: examples for the hooks

AttachmentSizeStatusTest resultOperations
user_op_comment_1.patch9.8 KBIdleFailed: Failed to install HEAD.View details

#14

Title:remove $op from hook_user» Remove $op from hook_user: Documentation
Component:base system» user.module
Status:needs work» needs review

It was missing hook_user_form. I also think that the implementation examples of the hooks should be added after this patch, due to the kittens. Nicely done!

AttachmentSizeStatusTest resultOperations
310212.patch9.64 KBIdleFailed: Failed to install HEAD.View details

#15

oh damn i deleted it because, i missed it because i read something with hook_nodeapi and remove of $op = 'form'

but i don't trust myself to be able to set to RTBC, anyone else, reading the documentation?

#16

There seems to be some inconsistent line-wrapping going on in the last version.

#17

Status:needs review» needs work

The last submitted patch failed testing.

#18

Status:needs work» needs review

this is the new version, just copyed http://drupal.org/files/issues/310212.patch and resolved the reject by hand.

AttachmentSizeStatusTest resultOperations
user_op_comment_3.patch7.7 KBIdleFailed: Invalid PHP syntax in modules/user/user.api.php.View details

#19

Status:needs review» needs work

Still some line wrapping issues - i.e.:

+ * The user account is being added. The module should save its
+ * custom additions to the user object into the database and set the saved

#20

i'm not sure about the load, login and logout hooks, see the old comment
it seems to be than the last line should be under load, so i did this

*   - "load": The user account is being loaded. The module may respond to this
*   - "login": The user just logged in.
*   - "logout": The user just logged out.
*     and insert additional information into the user object.
AttachmentSizeStatusTest resultOperations
user_op_comment_4.patch10.62 KBIdleFailed: 9244 passes, 0 fails, 1 exceptionView details

#21

Status:needs work» needs review

#22

It seems like "and insert additional information into the user object." is the prefix of "The module may respond to this". This patch includes that fix.

Also, looking at other implementations of hook_*, we see that there is an empty line between the first line and the next line of the documentation:

<?php
/**
* Perform periodic actions.
*
* Modules that require to schedule some commands to be executed at regular
* intervals can implement hook_cron(). The engine will then call the hook
* at the appropriate intervals defined by the administrator. This interface
* is particularly handy to implement timers or to automate certain tasks.
* Database maintenance, recalculation of settings or parameters, and
* automatic mailings are good candidates for cron tasks.
*
* @return
*   None.
*
* This hook will only be called if cron.php is run (e.g. by crontab).
*/
function hook_cron() {
 
$result = db_query('SELECT * FROM {site} WHERE checked = 0 OR checked + refresh < :time', array(':time' => REQUEST_TIME));

  foreach (
$result as $site) {
   
cloud_update($site);
  }
}
?>

This is also fixed in this patch.......... Documentation line margin set to 80.
AttachmentSizeStatusTest resultOperations
310212.patch9.17 KBIdleFailed: Failed to install HEAD.View details

#23

Status:needs review» needs work

The last submitted patch failed testing.

#24

Status:needs work» needs review

reroll

AttachmentSizeStatusTest resultOperations
310212_0.patch9.88 KBIdleFailed: Invalid PHP syntax in modules/user/user.api.php.View details

#25

Status:needs review» needs work

The last submitted patch failed testing.

#26

Any chance we can get a reroll? This is a significant doc bug.

#27

Status:needs work» needs review
AttachmentSizeStatusTest resultOperations
310212.patch7.5 KBIdleUnable to apply patch 310212_1.patchView details

#28

Whoops, wrong patch.

AttachmentSizeStatusTest resultOperations
310212.patch7.21 KBIgnored: Check issue status.NoneNone

#29

Status:needs review» needs work

Thanks.

Only the 'view' hook gets a $category. For example, module_invoke_all('user_logout', NULL, $user);.

+ * The module should validate its custom additions to the user object,
+ * registering errors as necessary.

Instead of 'user object', say $edit.

#30

Please have a look at #491972: Fix horrifying mess of crap in user module hooks.

I created the other issue without knowing about this one. In my patch, I removed all unecessary arguments of those hooks. I haven't yet looked at this, but if this contains better docs, we should merge it and if not, close one of them as duplicate.

Edit: I've also removed those unecessary & from $account, as that is an object...

#31

This issue seems to be fixed.

#32

Status:needs work» fixed

#33

Status:fixed» closed (fixed)

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