The example code uses the variable $user, which is not declared.

Is the code missing the declaration of the global variable, or should the variable be renamed $account?

CommentFileSizeAuthor
#8 672068.patch903 bytesjhodgdon
#7 672068.patch669 bytesjhodgdon
#4 672068.patch669 bytesjhodgdon

Comments

jhodgdon’s picture

Title: Documentation problem with hook_node_grants » hook_node_grants() example uses wrong variable
Version: 6.x-dev » 7.x-dev

Good catch! It looks like someone changed the first $user to $account, but not the second, a LONG time ago...

It's also a problem in Drupal 7. Should be fixed in both places.

http://api.drupal.org/api/function/hook_node_grants/7

avpaderno’s picture

I have fixed the example for Drupal 6.

jhodgdon’s picture

Issue tags: +Novice

Thanks! That one is in the contrib repository. For D7 we need a patch.

jhodgdon’s picture

Status: Active » Needs review
StatusFileSize
new669 bytes

Here's a patch for D7. Note that the Doxygen header has the first arg name for the hook as $user, not $account, so I went with that. It is more standard for Drupal to use $user than $account anyway.

jhodgdon’s picture

As a note, the D6 doc uses $account consistently (at least as of kiamlaluno's changes) in the doxygen and function example.

dries’s picture

It is probably best to always use $account, in order to avoid confusing (and security issues) with the global $user object.

jhodgdon’s picture

StatusFileSize
new669 bytes

Ah, good point. Here's a new patch.

jhodgdon’s picture

StatusFileSize
new903 bytes

Sorry. That was the old patch. Here's the new patch. I hope. This time.

dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)
Issue tags: -Novice

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