Dear all,
I was trying to use Rules to create activities that would then be reported by Heartbeat.
Goal: Whenever a user edits the (custom) text field 'status' of my Profile2 user profile, I want a status update like 'Username changed his/her status to I am happy' to appear in the Heartbeat stream.
For this, I performed the following steps:
- I created a Heartbeat template 'Status update' at
admin/structure/heartbeat/templates. The template's content is!username has changed his/her status to !status. - I created a rule 'Publish status updates to activity stream' at
admin/config/workflow/ruleswith the following properties:- Event: After updating an existing profile
- Conditions: Element has field
Parameter: Entity: [profile2], Field: field_status - Actions: Log activity for Status update
Parameter: Entity ID: <?php return 0; ?>, User ID: [profile2:user:uid], Entity target ID: <?php return 0; ?>, User target ID: [profile2:user:uid], Message ID: Status update, !username: [profile2:user:name], !status: [profile2:field-status]
Given this, I edited my own status and ran into the following error:
Notice: Object of class EntityValueWrapper could not be converted to int in rules_action_heartbeat_activity_log() (line 40 of /var/customers/forum/Server/sites/all/modules/heartbeat/modules/heartbeat_rules/heartbeat_rules.inc).
I took a look at heartbeat_rules.inc and after some debugging changed:
function rules_action_heartbeat_activity_log() {
// ...
foreach ($arguments as $key => $value) {
if (isset($template->variables[$key])) {
$variables['variables'][$key] = $value;
}
else {
$variables[$key] = $value;
}
if (in_array($key, array('nid', 'uid', 'nid_target', 'uid_target'))) {
$variables[$key] = (int) $variables[$key];
}
}
// ...
}
to
function rules_action_heartbeat_activity_log() {
// ...
foreach ($arguments as $key => $value) {
if ($value instanceof EntityValueWrapper) { // NEW
$value = $value->value(); // NEW
} // NEW
if (isset($template->variables[$key])) {
$variables['variables'][$key] = $value;
}
else {
$variables[$key] = $value;
}
if (in_array($key, array('nid', 'uid', 'nid_target', 'uid_target'))) {
$variables[$key] = (int) $variables[$key];
}
}
// ...
}
I am, however, not sure whether this is how it should be. Could somebody with more Heartbeat experience (which does not necessarily mean somebody older ;-)) take a look at this?
Best,
Kaspar
Comments
Comment #1
Stalski commentedPlease checkout the dev release for now.
Also use 0, instead of phpcode.
Let me know if problems are gone
Comment #2
Stalski commentedThis is fixed in latest dev. Thx for the report and solution.
I plan to do a better refactoring on that later.