Is it possible to include the acting user's avatar (picture) in the message row in Heartbeat?

Posted by admin

This is possible. You have several options to achieve that:

  1. You can put a token in the message template configuration, for instance !avatar. E.g.:
    <div class="avatar">!avatar</div><div class="message">!username just created !page.</div>

    • Using heartbeat API: In your call to the heartbeat api function, you create !avatar variable yourself.
    • Rules: If you are using rules, you have to assign this avatar variable to the corresponding token. The token is the clue here. You will have to create this in a custom module. There is an example at "creating your own custom tokens."
  2. You can implement hook_heartbeat_theme_alter where you alter the message. In heartbeat_example module is a great example on what you need. I prefer this way because it's cleaner to separate message types showing the user avatar or another icon for "status messages". E.g. Event calendar, blogpost icon, ...
  3. Confirm with the drupal theming, "heartbeat_message_row" is alterable in the template file and it's preprocessor. In the variables section ready for theming, $variable['message'] is available. This is a valid HeartbeatActivity object that holds the uid, and even the actor user object. So this makes it very easy to create the avatar (with imagecache or not).
  4. Display Suite way. Just create a field that will work with creates an avatar for the acting user.