I'm having trouble using this module. Read about this module and looked at the example and default modules and now i want to get going.

Trying to log an activity when a node is inserted

<?php
/**
 * Implementation of hook_nodeapi().
 */
function drupal_glue_heartbeat_nodeapi(&$node, $op, $arg = 0) {

	if ($op == 'insert') {
    drupal_glue_heartbeat_log_activity($node);
  }
}

/**
 * Callback function to hook into the closet updating action
 */
function drupal_glue_heartbeat_log_activity($node) {

	$message_id = 'drupal_glue_node_insert';
  $variables = array(
    '!user' => l(user_load($node->uid)->name, 'user/' . $node->uid),
    '@type' => $node->type,
		'!title' => l($node->title, 'node/' . $node->uid)
  );
  heartbeat_api_log($message_id, $node->uid, 0, $node->nid, 0, $variables, HEARTBEAT_PUBLIC_TO_ALL);
}

But the heartbeat table is still empty...

Comments

Michsk’s picture

I first ofcourse need to define the templates.

Stalski’s picture

Status: Active » Postponed (maintainer needs more info)

1) Indeed, the template with machine name "drupal_glue_node_insert" needs to exist first.
2) Also, always use the "!"-prefixed variable. This is not the same thing as the placeholders %, ! or @ used in the t-string replacement patterns.

Is this issue now ok or does it still exist? Please notify me if your problems are solved.

Michsk’s picture

1) I'm having trouble with setting up the template, i want to do it trough my module, but can't get it to appear. This is what is confusing me. I'm using heartbeat_defaults as my starting point. So here goes.
The heartbeat api tells me to use hook_defaults_heartbeat_template_info. But heartbeat_defaults is using heartbeat_defaults_heartbeat_template_info. Shouldn't that be heartbeat_defaults_defaults_heartbeat_template_info, thats what i would expect when viewing the api.

At this moment i'm trying function drupal_glue_heartbeat_defaults_heartbeat_template_info but that doesn't display my template.

My ctools_plugin_api is defined as following:

function drupal_glue_heartbeat_ctools_plugin_api($owner, $api) {
  if ($owner == 'heartbeat' && $api == 'heartbeat') {
    return array('version' => 1);
  }
}

2) ok, got it.

Stalski’s picture

Status: Postponed (maintainer needs more info) » Fixed

Hi,

The hook is called "heartbeat_template_info", so your module will declare drupal_glue_heartbeat_template_info() ... This is explained in the heartbeat.api.php file incorrectly. The "_defaults" is a left over from the heartbeat_example module where I miscopied the function to .api.php.

Most probably the error you are having, sorry for that. Change the hook function and it should work. I also adjusted the function names so it is correctly explained in the heartbeat.api.php file.
this has also been committed and pushed to git, with credits for you ofcourse.

Sorry for this inconvenience. I am always mad when documentation is not correct of inconsistent, so I understand you pain.

If you still have other issues, let me know.

Michsk’s picture

Ok that's clear, though i'm still unable to get this going.

Module name is drupal_glue_heartbeat.
Trying to get the hook trough drupal_glue_heartbeat_heartbeat_template_info() in my drupal_glue_heartbeat.heartbeat.inc file. My ctools_plugin_api() in drupal_glue_heartbeat.module is unchanged and still the same as in my comment above.

Here is my drupal_glue_heartbeat_heartbeat_template_info()

/**
 * Implements hook_heartbeat_template_info().
 */
function drupal_glue_heartbeat_heartbeat_template_info() {

  $heartbeatmessagetemplates = array();

  $heartbeatmessagetemplate = new HeartbeatMessageTemplate;
  $heartbeatmessagetemplate->disabled = FALSE; /* Edit this to true to make a default heartbeatmessagetemplate disabled initially */
  $heartbeatmessagetemplate->api_version = 1;
  $heartbeatmessagetemplate->message_id = 'drupal_glue_heartbeat_add_node';
  $heartbeatmessagetemplate->description = 'User adds a node, save user activity';
  $heartbeatmessagetemplate->message = '!username has added !node_type !node_title.';
  $heartbeatmessagetemplate->message_concat = '!username has added the following !types: %node_title%.';
  $heartbeatmessagetemplate->perms = TRUE;
  $heartbeatmessagetemplate->group_type = 'summary';
  $heartbeatmessagetemplate->concat_args = array(
    'group_by' => 'user',
    'group_target' => 'node_title',
    'group_num_max' => '4',
    'merge_separator' => ',',
    'merge_end_separator' => 'and',
  );
  $heartbeatmessagetemplate->variables = array(
    'username' => '',
    'node_type' => '',
    'node_title' => '',
    'types' => '',
  );
  $heartbeatmessagetemplate->attachments = array();
  $heartbeatmessagetemplates['heartbeat_add_node'] = $heartbeatmessagetemplate;

  return $heartbeatmessagetemplates;
}

It's the most basic version, copied from heartbeat.api.php. Only change is the messageid. Once i get this going i am willing to submit some kind of basic tutorial on how to get started with heartbeat trough a custom module and add it to the heartbeat book documentation. I saw your custom website which documents heartbeat but i couldn't find a real start on it, so again, once i get this going i am willing to publish about it.

Another thing i came across, though probably not an heartbeat issue, is that ctools help has documented that the api file shoud be MODULENAME.API.inc but you are using heartbeat.api.php. See ctools/help/export.html line 198. Again i think this is rather an ctools issue since more modules use api.php.

Michsk’s picture

Ok, got it working, finally.

The issue was that i had this drupal_glue_heartbeat module, in my drupal_glue module. So:
drupal_glue/module/drupal_glue_heartbeat/drupal_glue_heartbeat.module
and that seems not possible.

Stalski’s picture

Yes, that works fine.

The other thing is not as you understood it. I'll explain it in short.

Ctools allows other modules to defines API's. In this case, heartbeat is an API that defines its exportables through CTools. This means heartbeat is the "owner" of the api.
So if you want to export heartbeat message templates (provided by the owner "heartbeat") then CTools recommends to place those exportables in the file "yourcustommodule.modulewhoprovidestheapi.inc" ==> drupal_glue_heartbeat.heartbeat.inc ...
If you would export your views, it will be in drupal_glue_heartbeat.views.inc.

This has nothing to do with the .api.php hook I use correctly. This is only to show coders how to write the code.

I hope you understand it and thanks for the report.

Status: Fixed » Closed (fixed)

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