Remove $op from hook_user: Documentation

justinrandell - September 18, 2008 - 13:14
Project:Drupal
Version:7.x-dev
Component:user.module
Category:bug report
Priority:critical
Assigned:justinrandell
Status:needs work
Description

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.

AttachmentSize
hook_user.patch23.23 KB
Testbed results
hook_user.patchfailedFailed: Failed to apply patch. Detailed results

#1

justinrandell - September 27, 2008 - 09:02

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?

AttachmentSize
user.patch 25.69 KB
Testbed results
user.patchfailedFailed: Failed to apply patch. Detailed results

#2

catch - September 27, 2008 - 09:20
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

justinrandell - September 27, 2008 - 09:31

@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.

AttachmentSize
user.patch 25.8 KB
Testbed results
user.patchfailedFailed: Failed to apply patch. Detailed results

#4

justinrandell - September 28, 2008 - 07:00

will update this patch once HEAD is fixed.

#5

justinrandell - October 2, 2008 - 09:26

updated for HEAD, all tests pass.

AttachmentSize
user.patch 25.79 KB
Testbed results
user.patchfailedFailed: Failed to apply patch. Detailed results

#6

catch - October 2, 2008 - 11:06
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

Dries - October 6, 2008 - 11:28
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

Rob Loach - October 6, 2008 - 19:53
Status:needs work» fixed

Added the update module documentation for remove $op.

#9

Anonymous (not verified) - October 20, 2008 - 20:02
Status:fixed» closed

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

#10

catch - November 21, 2008 - 14:47
Status:closed» needs work

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

#11

Rob Loach - November 21, 2008 - 15:55

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

#12

catch - December 20, 2008 - 17:00

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

#13

dereine - January 3, 2009 - 10:54

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

TODO: examples for the hooks

AttachmentSize
user_op_comment_1.patch 9.8 KB
Testbed results
user_op_comment_1.patchfailedFailed: Failed to install HEAD. Detailed results

#14

Rob Loach - January 4, 2009 - 20:01
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!

AttachmentSize
310212.patch 9.64 KB
Testbed results
310212.patchfailedFailed: Failed to install HEAD. Detailed results

#15

dereine - January 4, 2009 - 20:22

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

Dries - January 5, 2009 - 21:54

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

#17

System Message - January 8, 2009 - 01:00
Status:needs review» needs work

The last submitted patch failed testing.

#18

dereine - January 9, 2009 - 00:21
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.

AttachmentSize
user_op_comment_3.patch 7.7 KB
Testbed results
user_op_comment_3.patchfailedFailed: Invalid PHP syntax in modules/user/user.api.php. Detailed results

#19

catch - January 11, 2009 - 19:58
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

dereine - January 11, 2009 - 21:16

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.

AttachmentSize
user_op_comment_4.patch 10.62 KB
Testbed results
user_op_comment_4.patchfailedFailed: 9244 passes, 0 fails, 1 exception Detailed results

#21

dereine - January 11, 2009 - 21:17
Status:needs work» needs review

#22

Rob Loach - January 11, 2009 - 22:00

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.

AttachmentSize
310212.patch 9.17 KB
Testbed results
310212.patchfailedFailed: Failed to install HEAD. Detailed results

#23

System Message - March 9, 2009 - 12:30
Status:needs review» needs work

The last submitted patch failed testing.

#24

dereine - March 18, 2009 - 20:26
Status:needs work» needs review

reroll

AttachmentSize
310212_0.patch 9.88 KB
Testbed results
310212_0.patchfailedFailed: Invalid PHP syntax in modules/user/user.api.php. Detailed results

#25

System Message - March 18, 2009 - 20:40
Status:needs review» needs work

The last submitted patch failed testing.

#26

moshe weitzman - June 22, 2009 - 15:17

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

#27

Rob Loach - June 22, 2009 - 15:39
Status:needs work» needs review
AttachmentSize
310212.patch 7.5 KB

#28

Rob Loach - June 22, 2009 - 15:42

Whoops, wrong patch.

AttachmentSize
310212.patch 7.21 KB

#29

moshe weitzman - June 22, 2009 - 15:48
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

Berdir - June 27, 2009 - 21:34

Please have a look at #491972: Fix and document hook_user_*().

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...

 
 

Drupal is a registered trademark of Dries Buytaert.