0

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)?

enter image description here

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

function hook_preprocess_field(&$variables) {

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

Though after a drush cc all && 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]]";
1
  • Thanks and I will. Updates one and two were basically a detour as I thought more about breaking this into elementary steps. Now that I have an access to alter OG's group-group field (and as it relates to Drupal Commons). My original question still stands: How to get group manager's email to display to a pending contributing member. Perhaps a meta topic, I'd love to have a progress log separate from the Answer Candidate and Original Post. – Rick Sep 5 '13 at 14:22
0

Well it appears I can get all of the users in the group via the following:

mysql> 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> 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> 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> select mail from users where uid =1\G

Or to put it more closely together:

mysql> 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(&$variables)
{

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

      if (isset($variables['items'][0]['#markup']) && 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'=> $variables['element']['#object']->nid,
          ':adminrole'=>'administrator member'
        );

        // execute query. Assemble a list of clickable email addresses. Strip the 
        // end comma.
        $result= db_query($query, $args)->fetchAll();
        foreach ($result as $record) {
          $grp_mgr_email = l($record->mail, 'mailto:'.$record->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'] = "";
      }
    }

}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.