How would I be able to create my own message type. Say for example I create a content type called "Calories", I use PHP to generate the title of the page based on the value of one of the fields , "Calorie Intake", in the content type. On my activity stream(site-wide) side panel it would show.... "Tom has created 50 calories." Lol, I want the activity stream to show the message "Tom has an intake of 50 calories" for the "Calories" content type specifically.

I realize out of the box, Commons has a default message for [User] created [Page Title].

I want to be able to change that message based on certain content types. Can someone give me some tips on how to solve my case? Thanks!

CommentFileSizeAuthor
#1 screenshot-activity.png26.88 KBthe604

Comments

the604’s picture

StatusFileSize
new26.88 KB

The examples in the screenshot are not part of my real case, i just decided to make a few examples to show what i'm trying to achieve. I was trying to see if commons used rules or views to change the way the message is displayed when a user likes, comments, or creates a node but I can't figure out how it is done to create my own custom messages for my own custom content types.

the604’s picture

My quickfix, just check for $node-type on function commons_activity_streams_node_insert($node){} in commons_activity_streams.module and call your own function in there to create your custom message for different content types.

Don't think it is a good idea to edit common's code though because you will have to add your changes on every version. Will try to find a better solution when I have time.

devin carlson’s picture

Status: Active » Fixed

You'll want to create your own message type and then implement hook_commons_activity_streams_message_selection_alter() and change the $message_type depending on the $hook and the $node->type.

Example:

/**
 * Implements hook_commons_activity_streams_message_selection_alter().
 */
function example_commons_activity_streams_message_selection_alter(&$message_type, $hook, $node) {
    // Provide a special message type that uses "User had an intake of X calories"
    // phrasing when a new calorie intake node is created.
    if ($hook == 'node_insert' && $node->type == 'calorie_intake') {
    $message_type = 'example_calorie_message';
  }
}

Status: Fixed » Closed (fixed)

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