I need to show on the user profile its connected heartbeat stream to everyone. For that I use the friendlist_activity module.
Out of the box I could not make this happen, as only logged users can read other users' connected heartbeat stream.
I've checked the module and found:


/**
 * Implementation of hook_heartbeat_register_access_types().
 */
function friendlist_activity_heartbeat_register_access_types() {
  return array(
    0 => array(
      'name' => 'Heartbeat relational activity',
      'class' => 'ConnectedHeartbeat',
      'path' => 'connectedheartbeat.inc',
      'module' => 'friendlist_activity',
      'access' => 'user_is_logged_in'
    ),
  );
}

I've commented out the last line which restrict access, so it works as I want, but this work around implies that I modify the contrib module, which I'd really would like to avoid. Any ideas on a better way to implement that?

Comments

Stalski’s picture

Well, in this case, in fact, you need to add your code in a new custom stream

function yourmodule_heartbeat_register_access_types() {
  return array(
    0 => array(
      'name' => 'My custom relational activity',
      'class' => 'MyConnectedHeartbeat',
      'path' => 'myconnectedheartbeat.inc',
      'module' => 'yourmodule',
      'access' => TRUE
    ),
  );
}

And then just define your class as extension of ConnectedHeartbeat:
myconnectedheartbeat.inc:


heartbeat_include('HeartbeatAccess');
// Did not test this, but it might work, otherwise you can still 
// use module_load_include function. 
heartbeat_include('ConnectedHeartbeat');

/**
 * Class MyConnectedHeartbeat
 */
class MyConnectedHeartbeat extends ConnectedHeartbeat {
  // Nothing that is different? or just override some methods. 
  // most of the time it will be for query overrides.
}
Stalski’s picture

Status: Active » Closed (works as designed)

I will set this to "by design" , however for drupal7 i will tackle this problem more convenient.
Most important thing is that you can do it without hacking heartbeat. That's what the hooks are for: customization. In the worst case scenario, you need to extend on HeartbeatAccess base class and take over the complete class body of ConnectedHeartbeat.

Greetz,
Stalski

Cap'taine Crochet’s picture

That's exactly what I was looking for. The code you provided works fine, but I had to change the heartbeat_include like that:

heartbeat_include('HeartbeatAccess');
heartbeat_include('ConnectedHeartbeat', 'friendlist_activity');

Thanks for your efficient support.

Stalski’s picture

Glad i could help.
I started an issue crosslink on http://heartbeat.menhireffect.be/page/documentation to this issue. Certainly something that needs to be covered in drupal7 by default. I will do this by moving this access to UI configuration.

get paid to upload’s picture

Title: Connected Heartbeat not shown to anonymous users » earn per download
Component: Code » Miscellaneous
Assigned: Unassigned » get paid to upload
Category: support » task
Status: Closed (works as designed) » Closed (cannot reproduce)

I like your way of writing and explaining the topics. Keep it up. I’m going to follow your blog.Thank you
very much….earn per download