How to use message_subscribe with organic groups

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

This is meant to be a reasonable tutorial for using message_subscribe with organic groups as the module exists as of (2014-02-25), but you should be able to extrapolate to make this work in other contexts. Since I found this module relatively complicated to set up and configure, I hope this helps someone have an easier time of it. As the module develops further, this documentation should be updated.

Currently (as of 2014-02-25) to get message_subscribe fully functional with og, you should use a patched version of the most recent git commit of the message_subscribe module. Without the most recent commit (commit 244a8879f722083d799a8c0522c368a44c5cda68), a single subscriber who is also the author of the group cannot receive messages. Hopefully the patches I recommend will get merged into a production release soon.

Issues:

To start, clone the git repository of the module and apply the following patches:

Download/Enable the following modules:

  • og
  • og_ui
  • message_subscribe
  • message_subscribe_ui
  • message_subscribe_email
  • views_ui

Message subscribe should enable multiple modules in addition to it's own as it depends on ctools, flag, message, and message_notify, which also depend on other modules (views).

Shell commands if you're using drush and a flavor of Linux/UNIX

git clone http://git.drupal.org/project/message_subscribe 
cd sites/all/modules/message_subscribe 
wget https://drupal.org/files/issues/email-notification-context-fix-2126689-20.patch && patch -p1 < email-notification-context-fix-2126689-20.patch 
wget https://drupal.org/files/issues/message_subscribe-subscribe_og_fix-1983226-7.patch && patch -p1 < message_subscribe-subscribe_og_fix-1983226-7.patch 
wget https://drupal.org/files/issues/message-rendered-fields-2205243-0.patch && patch -p1 < message-rendered-fields-2205243-0.patch 
drush -y en og og_ui message_subscribe message_subscribe_email message_subscribe_ui views_ui entity_token

Create an organic group type from "/admin/structure/types/add".

Once you have these modules installed, enable two flags from "/admin/structure/flags":

subscribe_og

-- under Flag Access --
- Add your organic group bundle to this field.
-- under Display Options --
- Check the boxes to display this link.

email_og

-- under Flag Access --
- Add your organic group bundle to this field ( you probably do not need anything else here)

At this point you should be able to subscribe/receive emails from a given organic groups. To test this you can:

  • Create an organic group
  • Subscribe to the group
  • Visit "/user"
  • Select the Subscriptions tab
  • You should see a table with
    | Group Name | Send Email | Unsubscribe |
  • To enable email, you will need to click on Send Email. You can use flag_rules to make "send email" a default selector, but currently users will need to manually choose to receive emails when subscribing.

If this all seems correct, you can now move on to creating a message architecture from "/admin/structure/messages/add".

Create the message "Group Content," with two message fields and save the message. One field will be the email subject and the other will be the email body.

Create three new fields on the message:

  • "Rendered Og Subject" -- machine name = field_rendered_og_subject) - text - Set "text processing" to filtered.
  • "Rendered Og Body" -- machine name = field_rendered_og_body - long text - Set "text processing" to filtered.
  • "Og ref" -- machine name = field_og_ref - entity reference - autocomplete

Create a Message view as table with the following fields:

  • Fields: User: User Name
  • Fields: Message: Rendered Og Body (Rendered Og Body) :
  • Fields: Message: Rendered Og Subject (Rendered Og Subject)
  • Filter by:Message Type: -- use the message type you created above.
  • Sort by:Message ID desc
  • Relationships:Message User uid <-- Add this relationship to User: User Name

Create a new module (example below is call sn):

sn/sn.info

name = Subscribe Notify 
description = Subscribe API for the Message and Message notify modules.  
core = 7.x

sn/sn.module

<?php

/**
 * Implements hook_node_insert() */

function sn_node_insert($node) { 
  $message = message_create(group_content'); 
  $wrapper = entity_metadata_wrapper('message', $message); 
  $wrapper->field_og_ref->set($node->og_group_ref['und'][0]['target_id']); 
  $options = array( 
    'rendered fields' => array( 
      'message_notify_email_subject' => 'field_rendered_og_subject', 
      'message_notify_email_body' => 'field_rendered_og_body', 
    ), 
  ); 
  $subscribe_options = array( 
    'subscribe message' => TRUE, 
    'email message' => TRUE, 
  ); 
  if (module_exists('message_subscribe')) { 
    message_subscribe_send_message('node', $node, $message, array('email' => $options), $subscribe_options); 
  } 
}

Make sure the line $message = message_create('MESSAGE_NAME'); of the module has the correct machine name of your message.

In the above module you can modify which type of message gets stored in the database. If you want a rendered subject and body, as this how-to outlines, you will want to make "subscribe message = FALSE". Having based this off of the message_notify_example module, my preference is to show messages in such a way that they contain all of the same information as email messages, with rendered fields. However, you can modify the view above to show the rendered message as one cell in the table, instead of showing the rendered subject and rendered body. It all depends on how you want your users to see messages on the site. Note: If you leave both $subscribe_options, 'subscribe message' and 'email message', set to true, your users will see two messages for each subscription, not ideal behavior. You should probably choose one or the other.

Enable the module.

Now you should be able to subscribe to a group, get emails about updated content, or you may choose to receive only on-site messages.

Help improve this page

Page status: Not set

You can: