I'm trying to alter the comment links in my Drupal output, and I think I have found the function I want to influence, which is function comment_node_view($node, $view_mode)
.
It is in the Comment module. The problem is I can't seem to effect it, when I try to override it by putting it in my Template.php file and add my theme_ to the function name? In my template.php it looks like this now:
function themename_comment_node_view($node, $view_mode)
if I take off the themename_ it causes an error saying I can't redeclare开发者_开发知识库 it. I can copy the comment module and edit it directly but I thought this was how I theme something?
Drupal themes can only implement theme functions (which include template preprocess and process functions) or alter hooks.
comment_node_view() is a hook, but it's not an alter hook (differently the hook name would end with "_alter").
Why cannot themes implement hook_node_view()
?
Because hook_node_view()
is invoked in comment_build_comment() using the following code:
// Allow modules to make their own additions to the comment.
module_invoke_all('comment_view', $comment, $view_mode, $langcode);
module_invoke_all('entity_view', $comment, 'comment', $view_mode, $langcode);
As it is also highlighted from the comment, module_invoke_all() invokes the hooks implemented in modules, not themes.
If you want to change how a comment is rendered, from a theme, you should create the comment.tpl.php template file for your theme.
The name spacing is 'hook_node_view' so you need to replace 'comment' (the name spacing used by the comment module) with your theme name:
function mytheme_node_view($node, $view_node)
Hooks:
http://api.drupal.org/api/drupal/includes--module.inc/group/hooks/7
hook_node_view:
http://api.drupal.org/api/drupal/modules--node--node.api.php/function/hook_node_view/7
Hope that helps :)
精彩评论