Hi,

trying to designate custom heartbeat templates using hook_heartbeat_template_info(). I adapted the logic from heartbeat.api.php, but to no avail. The hooks it not run, neither upon re-installing my custom module, nor upon flushing Drupal's cache. The hook is simply never called.

/**
 * Implementation of hook_heartbeat_template_info()
 */
function mymodule_heartbeat_template_info() {

  $heartbeatmessagetemplates = array();

  $heartbeatmessagetemplate = new HeartbeatMessageTemplate;
  $heartbeatmessagetemplate->disabled = FALSE; 
  $heartbeatmessagetemplate->api_version = 1;
  $heartbeatmessagetemplate->message_id = 'heartbeat_friendship_approved';
  $heartbeatmessagetemplate->description = 'User approved friendship';
  $heartbeatmessagetemplate->message = '!requestee and !requester are now friends';
  $heartbeatmessagetemplate->message_concat = '!requestee is now friends with %requester_name%.';
  $heartbeatmessagetemplate->perms = 4;
  $heartbeatmessagetemplate->group_type = 'summary';
  $heartbeatmessagetemplate->concat_args = array(
    'group_by' => 'user',
    'group_target' => 'requester_name',
    'group_by_target' => 'requestee',
    'group_num_max' => '4',
    'merge_separator' => ', ',
    'merge_end_separator' => 'and',
  );
  $heartbeatmessagetemplate->variables = array(
    '!requestee' => '',
    '!requester' => '',
    '!requester_name' => '',
  );
  $heartbeatmessagetemplate->attachments = array(
    'flagattachment' => array(
      'flags' => array(
        'like' => 'like',
      ),
    ),
    'flag_count_enabled' => array(
      'flags' => 0,
    ),
    'activitycomments' => array(
      'enabled' => 0,
      'activitycomments_node' => 0,
    ),
  );
  $heartbeatmessagetemplates['heartbeat_friendship_approved'] = $heartbeatmessagetemplate;

  return $heartbeatmessagetemplates;

}

Comments

Stalski’s picture

Status: Active » Fixed

You did implement the ctools hook as well? I just saw I did not mention that in the api description. So I updated that.
For your quicker response, an excerpt from heartbeat.api.inc:

*
* Note that the export hooks like
* ° hook_defaults_heartbeat_template_info,
* ° hook_defaults_heartbeat_stream_info
* ° hook_heartbeat_plugin_info
* are dependant on CTools. This requires you to include the
* hook_ctools_plugin_api() as well.

and

/**
 * Implement hook_ctools_plugin_api().
 *
 * This hook is needed to let ctools know about exportables.
 */
function hook_ctools_plugin_api($module, $api) {
  if ($module == 'yourmodule' && $api == 'yourmodule') {
    return array('version' => 1);
  }
}

If this was not the problem, please reopen this issue and we can take it on, but as your description, it's very likely it is.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

muschpusch’s picture

And you need :)


/**
* Implements hook_ctools_plugin_directory().
*/
function mynode_ctools_plugin_directory($module, $plugin) {
 if ($module == 'ctools' && ($plugin == 'export_ui' || $plugin == 'mynode')) {
   return 'plugins/'.$plugin;
 }
}

/**
 * Implementation of hook_heartbeat_plugin_info().
 * Built-in default plugins that can be used with heartbeat.
 */
function mynode_heartbeat_plugin_info() {

  if (module_exists('mynode')) {  
    $plugin_name2 = new HeartbeatPluginWrapper;
    $plugin_name2->disabled = FALSE; 
    $plugin_name2->api_version = 1; 
    $plugin_name2->plugin_name = 'mynode';
    $plugin_name2->label = 'bla bla';
    $plugin_name2->module = 'mynode';
    $plugin_name2->settings = array(
      'attachment' => 1,
      'count_enabled' => 1,
    );
    $plugin_names2['mynode'] = $plugin_name2;
  }

  return $plugin_names2;

}