I want to override the corolla_comment_submitted($comment) function because I need the usernames of some users to be a value from their profile depending on the node type. However, I can't figure out a way to access the node that the comment is connected to. I saw this page (http://api.drupal.org/api/drupal/modules--comment--comment.tpl.php/6) and to me it seems like I should be able to access the $node variable, however that doesn't seem to be the case.

if($node->type == "someType")
    {
        $name = 'someName';
     }
else
    {
        $name = theme('username', $comment);
     }

The code above doesn't seem to function.

Comments

nevets’s picture

I would try adding this to the themes template.info file

function THEMENAME_proprocess_comment(&$vars) {
  $node = $vars['node'];
  if ( $node->type == 'someType' ) {
     $vars['author'] = 'someName';
  }
}

The code uses 'author' instead of 'name' because it is a standard variable used in comment.tpl.php (see: http://api.drupal.org/api/drupal/modules--comment--comment.tpl.php/6)

Note you want to replace THEMENAME with the themes actual name.

iteria’s picture

It didn't work...

I couldn't even get

function themeName_proprocess_comment(&$vars) {
     $vars['author'] = 'someName';
}

to work and the name was hardcoded there. I placed the function in template.php. and changed themeName to my actual theme's name, but it didn't work at all. Am I missing something?

prakashp’s picture

Override the theme_comment_submitted() function by implementing the following function in the template.php file of your theme.

// replace themeName with the name of your theme.
function themeName_comment_submitted($comment) {
  $node = node_load($comment->nid);
  if ($node->type == "someType") {
    $comment->name = 'someName';
  }
  return t('Submitted by !username on @datetime.',
    array(
      '!username' => theme('username', $comment),
      '@datetime' => format_date($comment->timestamp)
    ));
}
iteria’s picture

It works! Thank you so much!