Adding group manager email to "membership pending" text When a user tries to join a private group in Drupal Commons she will see the following text: 


  Your membership request is pending review by a group organizer.


We'd like to give the user the ability to email (or otherwise contact via form) the group manager. Is it possible to update this text to add an email (to authenticated users only of course)? 



Update: It appears I may be able to accomplish this by hook_preprocess_field

function hook_preprocess_field(&amp;$variables) {

  if ($variables['element']['#field_name'] == 'group_group') {
        $variables['element'][0]['#markup'] .= "Group Mgr Email Placeholder";
  }
}


Though after a drush cc all &amp;&amp; drush cron, the page content remains the same. Am I using the wrong function?

Update 2: Well I now have a placeholder for email by using item instead of element. Next I'll move onto extracting the group managers and their emails to show to pending users.  

$variables['items'][0]['#markup'] .= " [[ place holder for emails]]";
Well it appears I can get all of the users in the group via the following:

mysql&gt; select * from og_membership where gid=10 and entity_type = 'user';
+-----+----------------------------+------+-------------+-----+------------+-------+------------+--------------+----------+
| id  | type                       | etid | entity_type | gid | group_type | state | created    | field_name   | language |
+-----+----------------------------+------+-------------+-----+------------+-------+------------+--------------+----------+
|  14 | og_membership_type_default |    1 | user        |  10 | node       | 1     | 1376756212 | og_user_node | en       |
| 146 | og_membership_type_default |   41 | user        |  10 | node       | 2     | 1378317628 | og_user_node | en       |
+-----+----------------------------+------+-------------+-----+------------+-------+------------+--------------+----------+
2 rows in set (0.00 sec)


But if I start with the group role I'm interested in (administrator member)

mysql&gt; select * from og_role where gid=10;
+-----+-----+------------+--------------+----------------------+
| rid | gid | group_type | group_bundle | name                 |
+-----+-----+------------+--------------+----------------------+
|  25 |  10 | node       | group        | non-member           |
|  26 |  10 | node       | group        | member               |
|  27 |  10 | node       | group        | administrator member |
+-----+-----+------------+--------------+----------------------+
3 rows in set (0.00 sec)


I can use it to find which users have that role: 

mysql&gt; select * from og_users_roles where gid=10 and rid=27;
+-----+-----+-----+------------+
| uid | rid | gid | group_type |
+-----+-----+-----+------------+
|   1 |  27 |  10 | node       |
+-----+-----+-----+------------+
1 row in set (0.00 sec)


Which gives me the chance to grab the email address of those users: 

mysql&gt; select mail from users where uid =1\G


Or to put it more closely together:

mysql&gt; select mail from users where uid IN 
( 
  select uid 
  from og_users_roles 
  where gid=10 and rid=27
);
+----------------------+
| mail                 |
+----------------------+
| webmaster@mysite.edu |
+----------------------+


1 row in set (0.00 sec)

Putting it all together, I ended up with this 

hook_preprocess_field(&amp;$variables)
{

    if ($variables['element']['#field_name'] == 'group_group')
    {

      if (isset($variables['items'][0]['#markup']) &amp;&amp; stristr($variables['items'][0]['#markup'], 'pending' )) {

        // prepare query lookup up email addresses of users with 'administer member' group roles
        $query = trim('
         select mail from users where uid IN (
            select uid from og_users_roles where gid=:gid and rid IN (
              select rid from og_role where gid=:gid and name=:adminrole
            )
          );
        ');
        $args = array(
          ':gid'=&gt; $variables['element']['#object']-&gt;nid,
          ':adminrole'=&gt;'administrator member'
        );

        // execute query. Assemble a list of clickable email addresses. Strip the 
        // end comma.
        $result= db_query($query, $args)-&gt;fetchAll();
        foreach ($result as $record) {
          $grp_mgr_email = l($record-&gt;mail, 'mailto:'.$record-&gt;mail) . ', ';
        }
        $grp_mgr_email = preg_replace('/,$/', '.', $grp_mgr_email);           


       // clear out the standard field and move to more noticable message
       drupal_set_message(t( strip_tags($variables['items'][0]['#markup']) . " Contact the group organizer(s): $grp_mgr_email"), 'status', FALSE);
       $variables['items'][0]['#markup'] = "";
      }
    }

}