Closed (fixed)
Project:
Drupal core
Version:
6.x-dev
Component:
documentation
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
21 Sep 2010 at 00:14 UTC
Updated:
27 Dec 2010 at 19:30 UTC
Jump to comment: Most recent file
In the documentation for drupal_alter(), the parameter $data is defined as structured array, but it could also be an instance of stdClass(), for example.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | drupal-alter-docs-D6-3.patch | 1.62 KB | rdrh555 |
| #18 | drupal-alter-docs-D6-2.patch | 2.05 KB | rdrh555 |
| #16 | drupal-alter-docs-D6-1.patch | 1.84 KB | rdrh555 |
| #11 | drupal-alter-docs-D6.patch | 1.83 KB | rdrh555 |
| #8 | 917670-drupal-alter-docs-D7.patch | 1.8 KB | mr.baileys |
Comments
Comment #1
mr.baileysCorrect,
drupal_alter('profile', $account);is an example where an object is passed to drupal_alter(), not an array. Patch attached for review.Comment #2
mr.baileysRemoved a trailing whitespace.
Comment #3
webchickWe should make 6 and 7 read the same here, which means fixing this in D7 first.
D7's description atm, btw, is "&$data The primary data to be altered."
Comment #5
avpadernoPrimary data is generic enough to not exclude an object as being passed to the hook implementation.
Should we change the documentation used for Drupal 7 too, or change the documentation for Drupal 6 to describe
$dataas primary data?Comment #6
avpadernoThe documentation for Drupal 7 cannot be the same for Drupal 6, though.
In Drupal 6,
drupal_alter()uses only a parameter passed by reference, while in Drupal 7 it uses three parameters that are passed by reference; calling$datathe primary data makes sense in that base.The documentation for Drupal 6 should also report the trick of using an array containing the index
'__drupal_alter_by_ref'to pass two by-reference arguments to the hook implementation. Right now, there is just a comment in the code that reports how to pass two arguments by reference to the hooks.Comment #7
mr.baileys@webchick: I'd left the D7 version alone since contrary to the D6 version, it's not buggy. I do agree it makes sense to reword it so the D6 and D7 versions are more similar.
@kiamlaluno: good point, I'll address that once the D7 patch is in and we're back to D6.
D7 patch attached, made some additional (minor) edits:
Comment #8
mr.baileysDear d.o., stop eating my patches...
Comment #9
avpadernoThe patch is good, IMO; it makes the description for Drupal 6 and 7 more similar of what they are now.
Comment #10
dries commentedCommitted to CVS HEAD. Moving to Drupal 6.
Comment #11
rdrh555 commentedPatch for D6.
Comment #12
jhodgdonI am not too happy with this:
I think the wording is very confusing, and it doesn't explain how to use the __drupal_alter_by_ref or how to use this in general. Also, this seems to imply that all ... args must be alterable, which isn't the case. And the alter_by_ref thing doesn't make sense to me, and implies there can only be two by-reference args -- I'm not seeing that in the code.
Comment #13
rdrh555 commentedYeah, struggled w/that ...how about this?
@param ....
drupal_alter() normally supports just one by reference parameter. Additional params that need to be passed by reference should be stored within the $data array using the key '__drupal_alter_by_ref' . They will then be passed on to the called hook_$type_alter functions.
Comment #14
jhodgdonThe @param for ... needs to say that it's for additional arguments that are not passed by reference, which is still not mentioned in your new proposal.
Probably the stuff about __drupal_alter_by_ref should go in the @param for $data, since that's where you pass it in?
Comment #15
rdrh555 commentedAgreed.
Comment #16
rdrh555 commentedRevised patch.
Comment #17
jhodgdonOK, this is much better.
The only little thing I would change now is that some places, it says hook_TYPE_alter() and some places, it says hook_$type_alter. I think the first form is better?
Hmmm...
" Additional params that need to be passed by reference should be stored using an array with the key '__drupal_alter_by_ref'."
Maybe this would be better as:
If you need to pass additional parameters by reference to the hook_TYPE_alter() functions, include them as an array in $data['__drupal_alter_by_ref']. They will be unpacked and passed to the hook_TYPE_alter() functions, before the additional ... parameters (see below).
Also, I think we should say "parameters" not "params" in the "..." section. How about:
Any additional parameters will be passed on to the hook_TYPE_alter() functions (not by reference), after any by-reference parameters included in $data (see above).
Thoughts?
Comment #18
rdrh555 commentedThoughts are: consistency is key, and, by merging in proposed changes, this patch now clearly communicates the handling of the different(additional) parameters. Thank you for the suggestions.
Comment #20
jhodgdonThis is fine. Ignore the "test" failure - the bot is not working right now for D6.
Thanks!
Comment #21
gábor hojtsyHum, it does not look like that $type can be an array.
Comment #22
jhodgdonYou are right -- in D6 $type cannot be an array. Sorry for not noticing that in my review -- I must have been looking at the D7 code by mistake. That does need to be removed from the patch.
Comment #23
rdrh555 commentedNew patch per Gabor's comment:
Comment #24
rdrh555 commentedaugh! d.o. grabbed it twice somehow and I don't even know if there is a way to "unsend", sorry!
Comment #26
jhodgdonThanks, looks good! And ignore it if the bot says it doesn't apply - the patch is fine.
Comment #27
gábor hojtsyGreat, thanks committed.