Hello,
A simple theming question. I try to find a solution to display a "comment" link directly in the HB message. If it's possible, I'd like to show the react form only if a user click on "comment" under the message. Too many textareas on the stream are not so nice :)

The ideal would a be a comment counter and a link to add another comment.

How would you do that ?

Thank you.

Comments

Stalski’s picture

Status: Active » Closed (works as designed)

Did you check the example module? and the demo site? It's explained there how yo can achieve that facebook effect ;)
FYI
The comment box is just hidden with css by default. I added a button throught hook_heartbeat_messages_theme_alter, that then in js toggles that hidden fieldset of comments.

Anonymous’s picture

Sorry Stalski, but I don't find the informations to achieve this effect on the demo site.
Anyway, I try to do something with css and fieldset... Something like this in message-row.tpl.php
It works. The only problem with this solution is that every attachment goes in the fieldset, even the "flag button", of course...

    <?php if (!empty($message->content['widgets'])) : ?>
<fieldset class="collapsible collapsed">
<legend>
Comments</legend>
 <div class="heartbeat-attachments">
      <?php print $message->content['widgets']; ?>
    </div></fieldset>
    <?php endif; ?>

Thank you

Stalski’s picture

You can just add buttons, that is the trick. Just do dsm in the hook i said and you will see what is in there. Just add a button to "buttons" and hook js behavior on it.

Anonymous’s picture

I understand the concept, now I try to find the correct way to add a button...

Anonymous’s picture

I've tried to put this code in a custom module but it's not the correct solution. It doesn't work. What am I missing or doing bad ?

<?php

function _heartbeat_comment_button($object = NULL, $link_text = '') {

  $comment_count = isset($object->additions->comment_count) ? $object->additions->comment_count : 0;
  $link_title = $comment_count;

  $arguments = array('attributes' => array());

  if ($comment_count > 0) {
    $class = 'heartbeat-comment-count commented';
  }
  else {
    $class = 'heartbeat-comment-count uncommented';
  }

  if ($link_text != '') {
    $class .= ' heartbeat-comment-button';
    $arguments['attributes']['title'] = $link_text;
  }
  else {
    $class .= ' heartbeat-comment-counter';
  }

  $arguments['attributes']['onclick'] = 'javascript:Drupal.heartbeat.toggleComments(this); return false;';

  return '<span class="' . $class . '">' . l($link_title, $_GET['q'], $arguments) . '</span>';
}


function _heartbeat_theme_alter(&$messages, HeartbeatAccess $stream) { 

  foreach ($messages as $key => $message) { 

    $message->content['buttons'] = theme('_mvcfinal_heartbeat_comment_button', $message);
    $content .= theme('heartbeat_message_row', $message);
} 
  return $content;
} 

?>

Thank you.

Anonymous’s picture

From the code you provide on the demo website. I've also tried this (in a custom module)

<?php

function _heartbeat_comment_button($object = NULL, $link_text = '') {

  $comment_count = isset($object->additions->comment_count) ? $object->additions->comment_count : 0;
  $link_title = $comment_count;

  $arguments = array('attributes' => array());

  if ($comment_count > 0) {
    $class = 'heartbeat-comment-count commented';
  }
  else {
    $class = 'heartbeat-comment-count uncommented';
  }

  if ($link_text != '') {
    $class .= ' heartbeat-comment-button';
    $arguments['attributes']['title'] = $link_text;
  }
  else {
    $class .= ' heartbeat-comment-counter';
  }

  $arguments['attributes']['onclick'] = 'javascript:Drupal.heartbeat.toggleComments(this); return false;';

  return '<span class="' . $class . '">' . l($link_title, $_GET['q'], $arguments) . '</span>';
}

function _mvcfinal_heartbeat_action_buttons($message, $args = array(), $node = NULL) {

  global $user;

  static $relationship_type = NULL;

  if (!isset($relationship_type)) {
    $all_relationships = user_relationships_types_load();
    // 1 is the friend relation type
    $relationship_type = $all_relationships[1];
  }

  $links = array();

  if (!empty($args['wrap'])) {
    $links[] = '<div class="heartbeat-action-buttons">';
  }

  $links[] = '<span class="heartbeat_times">' . theme('heartbeat_time_ago', $message) . '</span>';
  //$links[] = '<span class="heartbeat_intersection">  </span>';

  if (!empty($args['comment'])) {
    $links[] = _theme_heartbeat_comment_button($message, t('comment'));
  }

  if (!empty($args['member']) || !empty($args['group'])) {
    $links[] = '<span class="og">' . og_subscribe_link(node_load($message->nid_target)) . '</span>';
  }

  if (!empty($args['friend']) && $message->uid != $user->uid) {
    // For friendlist module
    //$friend = friendlist_ui_get_link('add', $message->uid, 1);
    //if (!empty($friend)) $links[] = '<span class="friend">' . $friend . '</span>';

    $links[] = '<span class="friend">' . theme('user_relationships_request_relationship_direct_link', user_load($message->uid), $relationship_type) . '</span>';

  }

  if (!empty($args['wrap'])) {
    $links[] = '</div>';
  }

  return implode('', $links);
}

function mvcfinal_heartbeat_theme_alter(&$messages, HeartbeatAccess $stream) { 

   $attachment = array();
    $comment = $message->template->attachments['heartbeat_comments'];
    $buttons = array('friend' => TRUE, 'comment' => $comment);

    $messages[$key]->display_time = FALSE;
    
   
  foreach ($messages as $key => $message) { 

    $message->content['buttons'] = theme('_heartbeat_comment_button', $message);
    $content .= theme('heartbeat_message_row', $message);
    
    if (empty($messages[$key]->template->attachments)) {
      $messages[$key]->template->attachments = array();
    }
    
    if (!empty($buttons) && is_array($buttons)) {
      $attachment = array('_rendered' => _mvcfinal_heartbeat_action_buttons($message, $buttons, $node));
      array_unshift($messages[$key]->template->attachments, $attachment);
   }
} 

}
?>

But it doesn't work. One thing I don't understand is that even if I set the display time to FALSE, the time is displayed on each message.