Closed (works as designed)
Project:
Drupal core
Version:
7.x-dev
Component:
comment.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
2 Mar 2007 at 16:39 UTC
Updated:
17 Oct 2009 at 06:59 UTC
Jump to comment: Most recent file
Comments
Comment #1
jax commentedThe first patch doesn't actually work. This one does.
Comment #2
RobRoy commentedCode style needs work, using TABs. Also, you should be able to omit that helper function.
Comment #3
dmitrig01 commentedComment #4
jax commentedHere's one without the helper function and without tabs. By the way, the reason this cannot be done with an array_merge like for the 'form' hook is that in the case the $comment variable is an object is stead of an assoc array.
Comment #5
jax commentedYet another solution to the problem. Here I use casts to transform the object to an array and back so that we can use array_merge to combine the old and new comment. Could someone please review this?
Comment #6
killes@www.drop.org commentedThis looks like a good idea.
The implementation shows that somebody should go through all the comment hooks and standardize all their arguments and return values to arrays...
Comment #7
jax commentedI started converting everything to assoc arrays and came across the drupal_unpack() function (line 1016) which requires an object. Is there an alternative that takes an array?
Because if I need to convert the $comment to an object before passing it to unpack() and then back to an array it is no better than my patch. Any suggestions?
Comment #8
jax commentedThis view hook is called inside theme_comment_view. So that means that this function receives an object. If we want to convert the object to an assoc array we must look higher up the chain.
The function
is called from
It is in this last function that right before theme('comment_view', $comment) is called there is the call to
which expects an object. So if I change everything to assoc I will have to do the array -> object cast here in stead of in the theme_comment_view function.
Currently drupal_unpack is used in not too many places:
The only way I currenlty see how to fix this is to either ban objects or assocs altogether. Or I can see to modify drupal_unpack to accept an array and modify the session.inc and user.module files as well. Since this is not a small work I would appreciate some feedback on this.
Comment #9
jax commentedcasetracker solves the problem by defining the hook's signature as
Then, wehen comment is passed as an object and no merge happens you can modify the object directly. I noticed this because my patch breaks the casetracker module.
So when $comment is passed as an array and the hook puts it back together with array_merge you cannot modify the array directly (your changes will be lost) but you need to return the new and modified values as an array. When $comment is passed as an object you can modify it directly to make your changes available.
api.drupal.org defines the signature with the ampersand so this bug/feature might break anywhere in the future. I really would like to suggest banning db_fetch_object from the drupal api and use assoc arrays everywhere, or the other way around. But mixing those two together everywhere isn't the brightest idea either.
Comment #10
catchStill applies with fuzz and offset, but looks like it breaks APIs so moving to D6.
Comment #11
catchComment #12
jax commentedA lot of this will go away once PDO is in use with D7. So, for my part this can be closed.
Comment #13
catchNow you can. http://api.drupal.org/api/function/hook_comment_view/7