I am designing a new theme and I want the links for comments (displayed along with nodes) to be generated in a manner that is very different than what comment_link() from comment.module currently does.

What is the clean way to do this? I do not want to hack the comment module since it will be more cumbersome to make the changes all over again when I do an upgrade.

Is there a way in which the actual comment_link() is not called but my_function() is called?

Comments

nevets’s picture

It depends on what you want do node links and which template engine you are using. The links under nodes and under comments use the same theme function (theme_links) which you can easily override if you are using PHPtemplate.

You can read about overriding theme function using PHPtemplate at http://drupal.org/node/11811

varunvnair’s picture

Thanks for the answer. Let me be a little more specific. I am using the phpTemplate theme engine (CVS version).

comment.module has a function called comment_link that provides some links to be printed alongwith nodes and comments. I want to finely control the behaviour of this function. I can go inside this module and change the code to my liking but I wanted to know if there was a way in which I could cleanly override it.

theme_links merely themes the links that are passed to it by the caller.

I don't care much (right now) about the themeing. comment_link adds some stuff that ends up in node->links. What I want to control is what node->links eventually has.

A small e.g. The way comment_link() is implemented right now it returns "add new comment" if the node has no comments and "5 comments" if the node has 5 comments. I want to change the "add new comment" to "0 comments". How do I do this?

Thanks for your time.

My Drupal-powered Blog: ThoughtfulChaos

nevets’s picture

For that kind of change you would need to modify the code in the comment module.

varunvnair’s picture

I thought so. I poked around in many cases and I finally came to the conclusion that I will have to hack the comment module itself.

Actually I changes I want to make are very extensive and it is very difficult to provide an extension mechanism that would allow very radical changes. I am going to keep a hack.log of all the changes I make so that whenever I do an upgrade I make those changes on the new module again.

Thanks for the help. Have a nice day.

My Drupal-powered Blog: ThoughtfulChaos

druvision’s picture

Here is a nice example of modifying the comment_link function. The modification shows the add comment link / form only in the full node display. I would be glad if somebody commits it, or submits it as a patch, since this is a good general idea, as I pointed out in http://drupal.org/node/49428.


          if ($node->comment == 2) {
/* AL New */
if (substr ($_GET['q'], 0, 5) == 'node/') {
/* AL End */
            if (user_access('post comments')) {
              $links[] = l(t('add new comment'), "comment/reply/$node->nid",
array('title' => t('Add a new comment to this page.')));
            }
            else {
              $links[] = theme('comment_post_forbidden');
            }
/* AL New */
}
/* AL End */

Amnon
-
Personal: Bring Dolphin's Simple Joy to your Work - Job - Career
Professional: Small business web hosting strategies, Drupal Hebrew Hosting