Closed (fixed)
Project:
Drupal core
Version:
6.x-dev
Component:
comment.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
14 Feb 2009 at 18:23 UTC
Updated:
28 Jan 2012 at 11:11 UTC
Jump to comment: Most recent file
Comments
Comment #1
mr.baileysHmmm, I'm fairly certain that
comment.modulealready has this. See for example this snippet (from D7, around line #1070):(Also, I think calls like
drupal_alterandmodule_invoke_allprobably shouldn't be called from the theme layer, as themeing should only be concerned with presentation.)If you still think this is a bug, please open a support request and describe in detail:
Comment #2
neochief commentedThanks for reply, mr.baileys. Your code affects only single-coment view (for example, when you replying to comment). But if you'll see little lower in the code (line #1132) in place where rendering comment threads, you'll see that this alter is not triggerring at all. I agree that altering in theme layer is not a best way. But invoking the hooks as well (#1830, #1865). Maybe we should place these hooks into comment_render and do averything there. If so, give me a shot and I'll prepare the patch.
I need these alters for my module ajax_comments. Currently I have an ability to override comment links only in preprocess function. And it would be enough for me, if preprocess functions called for theme functions as well. But they not. And if theme don't have a comment.tpl.php, I have no way to alter comment links at all.
Comment #3
mr.baileysThanks for the clarification. I do think this is a feature request though, as nothing is currently broken (marking as such). Can you supply a new patch for review?
Comment #4
neochief commentedHere it is.
Comment #6
neochief commentedComment #7
neochief commentedComment #9
neochief commentedHuh? Invalid PHP syntax? What is it? Patch is straight forward.
Comment #10
mr.baileysNot sure, I've applied the patch locally without issues. You can request a re-test.
Comment #11
neochief commentedI think it's because of #332967: Detect non-unix newlines . Here's a patch with LF only.
Comment #12
neochief commentedComment #13
neochief commentedBumping this up, as all test passed successfully.
Comment #14
moshe weitzman commentedOne approach that would be more work but much more useful would be to make comment thread use drupal_render() style array. then hook_page_alter() could fiddle with comment links. That need not stop this patch though.
Comment #15
catchhttp://api.drupal.org/api/function/hook_link_alter/7 needs updating even if this is only an interim patch.
Comment #16
neochief commented@moshe weitzman, yes, I agree and I can handle it. But maybe it should be done in a new issue, and this one just commited as-is?
@catch, sorry, I don't understand what update do you mean. The hook_link_alter's concept wasn't changed by my patch at all, I just added it to missing places.
Comment #17
catchneochief - the phpdoc for hook_link_alter() is completely wrong. This is more the fault of the node rendering patch than this one, but we should at least state explicitly that it works for comments now. Probably the parameter should be $comment instead of $node as well.
Comment #18
voxpelli commentedThis really needs to be fixed in Drupal 6 (and probably 7) because as it is now hook_link_alter() is run inconsistently on comments which isn't very good at all and should be considered a bug. It would have been a feature request only if hook_link_alter() was never run on comments.
Anyone having a plan on how we can solve this issue? Since we're in code freeze for D7 any plans on doing new cool solutions to solve this problem is no longer feasible, so the simple fix that the current patch contains should be applied on both D7 and D6 - since it's a bug fix and shouldn't be affected by any code freeze.
Comment #19
catchcomment links can now be alter in hook_comment_build_alter(), so moving this back to 6.
Comment #20
neochief commentedOkay, so can anybody review patch for 6.x? It suppose to be working.
Comment #21
mr.alinaki commentedPatch for 6.x fully works for me. I use it in hack for Comment Edited module to remove "edit" link, for example.
Comment #22
mr.alinaki commentedComment #23
gábor hojtsyHm, flat expanded and thread expanded are the only comment modes where links are shown but not altered, or are the others covered by existing code?
Comment #24
neochief commentedGábor, there are no links in other modes at all.
Comment #25
gábor hojtsySo in short, the issue here is that when single comments are displayed, Drupal 6 uses this code:
However, when multiple comments are displayed, the theming layer requests these links and do not allow for altering:
The suggested patch merely makes link altering consistent by adding link altering to these theme functions. To be done outside the theme functions, we'd need to introduce an API change (pass on links in some way to the theme function), so the best we can do is to add more logic to this theme function.
Existing themes will not benefit, so module authors will still not be able to rely on this, but can bug themers to fix their themes if incompatible.
Looking at the patch though, the issue here is that the patch passes on $comment instead of $node to link altering, so it does not use the API as documented / expected. This should be fixed and retested.
Comment #26
neochief commentedOnly two theme functions are affected — theme_comment_flat_expanded() and theme_comment_thread_expanded(). I think they are not most used theming functions of all times, moreover I didn't seen their usage at all for 2 years of my practice, but anyway, even if someone will reiplement them in their own theme. they will work as usual. Yes, they will not benefit, but they will not harmed as well. If themer reimplements comment_flat_expanded for example, and uses old way inside, what we can do at all? I guess nothing.
In D7 this code is almost the same as with my fix, so I think this patch fix problem in right way. Should we change docs of http://api.drupal.org/api/function/hook_link_alter and change it's parameter name to "$object" in place of "$node"?
Comment #27
gábor hojtsy@neochief: that smells like an API change for me, since the other (only) existing place for link altering on comments passes on the node, not the comment.
Comment #28
neochief commentedWell, we have three options:
1. Leave API unchanged, use my fix to fix the bug (we use undocumented feature of hook_link_alter of D6).
2. Rename parameter of hook_link_alter to state that it can be used not only for nodes (as it factually is in D7) + use my fix.
3. Provide some other hook like hook_comments_link_alter() and alter links there. But it's most useless and non-perspective way, as in D7 we already have proper solution.
As for me, the first one is the best, as it will not harm anything on existing sites at all. The second is less preferable, as it's definatelly API change, but as catch said, why should we don't say that it works for comments to?
Comment #29
gábor hojtsy@neochief: show me the code where it is factually being used with something other then a $node and it is not in your patch. I could not find an example. (We need these in D6 of course).
Comment #30
neochief commentedHow could I show you if it doesn't make sense currently without this patch? Anyways, here's example from AJAX Comments:
It works perfectly for everyone in about a year (with the patch of course, as without it it just can't change the links).
Comment #31
gábor hojtsy@neochief: ajax_comments assuming it gets a $comment from Drupal when it is not does not prove Drupal will pass a $comment. The only code I found altering links I quoted above at #25, and that passes on a $node. Once again, passing on $comment is a breach of the API, unless you can show a Drupal core code excerpt from Drupal 6, where it passes something other then a $node.
Comment #32
neochief commentedGábor, if we will pass $node there, it will not make any sense, as global point of this patch is to allow alter comment's links, but node node's. If we have comment info, we can get node from it, but if we pass node, we can't know which comment has triggered the hook. I do agree, that there are no other example, but links are being used only in comments and nodes, and the problem is just here.
Comment #33
gábor hojtsyYes, we have a not too useful API, I can wholeheartedly agree. It allows you to alter comment links, but does not tell you the comment. That is the API available in Drupal 6, and that is the API that should be available regardless of point version of Drupal 6. So we should not pass $comment in place of $node, since Drupal 6 clearly and universally passes a $node there, including the time handling single comment links. While this is not nice, this is how the Drupal 6 API is defined, so this is how it is going to work. Drupal 7 was open to fix such issues, and as discussed above, it did add opportunities to alter comment links properly.
Now what we can do in Drupal 6 is to add these two missing link alters in a way that conforms to the API. So we need to pass on the $node, not the $comment according to the Drupal 6 API. That is as far as we can go without API modification.
Comment #34
neochief commentedAgree. Anyways, patch in #11 contains $node, as param, so it mirrors your statement (
drupal_alter('link', $links, $node);) Is it okay?Comment #35
gábor hojtsyYes, except patch in #11 is not good for other reasons for Drupal 6, as it changes even more other (theming) APIs. The code I'm arguing for is the one D6 patch from the start but using $node, not $comment for link altering.
Comment #36
neochief commentedI'm happy with #11. There are other possible solutions for altering comment links with comment context, so let it be as in #11.
Comment #37
gábor hojtsyI've already explained #11 is not comittable to Drupal 6.
Comment #38
mr.alinaki commentedI use patch from #11 in comment edited module. I can use it in OG Comments module or Comment Permissions.
Comment #39
zroger commentedGabor, here's what you've requested, so we can get this in.
This patch takes the original d6 patch, but passes $node instead of $comment to drupal_alter for API consistency. In my testing, I am able to consistently alter the links, regardless of whether I am looking at a single comment, or a list of comments.
Comment #40
Oleksa-1 commented#39 is working for me. Thx
Comment #41
pivica commentedTested 39# with and without dialog_comment module and its working OK. Is there any reason this can't get into the core?
Comment #42
elliotttf commentedI concur that #39 is working and would like to see this make its way to core.
Comment #43
zroger commentedsomeone care to RTBC this?
Comment #44
robloachAlthough I'd rather take the approach in #11, Gabor is right in that being an API change. Fixing it in the theme function ala #39 is the way to do it now. Setting this to RTBC.
Comment #45
gábor hojtsyThanks, committed to Drupal 6.
Comment #47
salvis(Just for the record, this fix has appeared in 6.16.)
I agree that $node needs to be passed, but could we not pass $comment in addition to $node? This would slightly extend the API but not break it. Not passing the object whose links are being altered is a bug in the API...
A usable hook_link_alter(&$links, $node, $comment = NULL) would allow Forum Access to do its work without abusing $modulename_preprocess_comment() and thus conflicting with Advanced Forum.
@Gábor Hojtsy: Is there a chance for getting a follow-up patch committed?
Also, the documentation hasn't been updated. There's a comment attached to http://api.drupal.org/api/function/hook_link_alter/6, but this needs to be documented in core.php. I'll volunteer to update it if we can add $comment... :-)
Comment #48
sunThis indeed looks pretty odd to me. I'd be fine with the suggested solution.
Comment #49
zroger commentedhook_link_alter() actually receives the $comment object, not the $node object. The documentation for hook_link_alter() should be updated to use $object to be similar to hook_link.
In general, hook_link_alter() documentation needs a complete overhaul to mention that it works on comment links as well as node links.
Comment #50
salvisEither you're confused, or you've hacked your copy of core, or your theme does this for you, but plain core always passes $node, as discussed earlier in this thread and implemented by your own (!) patch in #39.
Please check the facts...
Comment #51
sunIt clearly looks like the patch that went in should have passed $comment instead of $node, because after all, all of this is about comments, not nodes.
145 critical left. Go review some!
Comment #52
Fogg commentedsign me up on this!! Would help using Forum Access and Advanced Forums together. Thanks!
Comment #53
salvisNo, this was discussed in this thread. hook_link_alter() is currently documented as being invoked for nodes (only!) and receiving a $node. In one place it was already called for comments (but still with $node!), but not consistently, and the effect of the committed patch is to always call it for all comments.
catch already suggested in #17 to pass $comment instead of $node, but this would have broken the API. So, in the current 6.16, $node is being passed in all cases.
What I'm proposing here is to pass $comment in addition to $node, in order to not break the API, but still receive the required information. This is a no-brainer...
Comment #54
salvisReverting #49...
Comment #55
sunI think this is good to go.
Comment #56
dave reidEither way the documentation for hook_link_alter() needs to change *along* with this patch, even if its documenting another parameter.
Comment #57
dave reidDamnit I take that back. I forgot the hook docs are in contrib for D6 and below.
Comment #58
salvisI already volunteered in #47 to update the docs once #47 is committed.
If someone else wants to do it, I'm fine with that, too, of course. :-)
Comment #59
michelle+1 from me for #47. I'm looking at changing from messing with links in the theme to doing it in the alter for Advanced Forum so I can avoid conflict with other modules. But I can't do that if I don't know what comment the links are for because I have no way of knowing if it's a comment I should be styling.
Michelle
Comment #60
moonray commented+1 on the patch in #47 as well.
Comment #61
Fogg commented+1 for patch in #47.
Comment #62
miro_dietiker+1 for #47 again.
Quick node:
Please make sure these modules will commit asap a fix right after:
Views
Forum Access
Advanced Forum
Comment #63
miro_dietikerOne more question: When skimming through the code of comment.module i see
A hook_link with second parameter $node @406 (well i know, according to the docs...)
A hook_link invocation with the parameter $node submitted $comment 3 times @951, @1746, @1774
This seems odd to me. We should rename $node to something like $object, even if the docs are outside. This would then param name hit:
Am i completely wrong?
Comment #64
salvisI agree with you that comment_link() should have an $object parameter rather than $node, because it responds both to
$type == 'node'and$type == 'comment'. This deserves to be cleaned up, IMO, but it's outside the scope of this issue here, which deals with hook_link_alter() only. http://api.drupal.org/api/function/hook_link calls it $object. Modules that respond only to$type == 'node'are fine to call it $node, IMO.Care to open a new issue for comment_link()?
For hook_link_alter() we always pass the $node in the same position, so we're fine here.
Comment #65
eugenmayer commented+1 for #47
Those feature should become very handy
Comment #66
miro_dietikerOK then. More reasons for this to get it committed.
These patch suggestions already profit from the alter introduced here:
Forum Access
#525392: Advanced Forum 1.x and Forum Access Incompatibility
Advanced Forum
#768348: Use hook_link & alter for manipulating node/comment links
No more hacks workarounds needed. Reduced complexity due to less link rebuilds, improved speed, improved extensibility. Please make this true.
Comment #67
AntiNSA commented+1
Comment #68
gausarts commentedSubscribing. Thanks
Comment #69
Fogg commentedHi folks,
i don't want to push any more than necessary, but is there any chance of getting this submitted to drupal6 ? We are really waiting on this!
Thanks for any kind of update here!
Fogg
Comment #70
walker2238 commented+1
Comment #71
ayalon commentedawaiting this too...
Comment #73
gábor hojtsyOk, committed #47. Let the contrib rolling going including updating the hook docs.
Comment #74
dave reidHook docs are updated. Feel free to review when the update on api.drupal.org.
Comment #75
miro_dietikerVery happy to see this fixed. Thanks a lot guys!
Polled the referred module issues to consider the new feature as suggested.
Comment #76
Fogg commentedWow, took quite a while, but thanks! Finally thing get moving!
Cheers.
Comment #77
salvisThanks for updating the docs. I'd suggest three minor additions:
We should probably also document the fact that $comment hasn't always been available. This will save head-banging remote debugging sessions.