I'm using Drupal 7 to create an intranet site. I'm using OG groups to create committee and department pages. I want to create a field in a "Meeting Minute" node type where a list is populated with all group members. The node author could then select whether the committee member was present or absent at a meeting.

I'm able to use an Entity Reference field to select from all users on the site, but I want to limit these checkboxes to just group members.

I'm striking out here; any ideas on where to start would be much appreciated.

Using the OG 7.x-1.x branch.

UPDATE: I have tried to use the "Entity Reference View Widget" module to accomplish this, but that doesn't seem to work either.

I'm going to try to restate this for clarity — I need a field on a node edit page that allows me to select one or more users who are also members of a group from the organic groups module.

1 Answer 1


Use hook_form_alter to do a entity field query or SQL query to get a list of UIDs that belong to 1 group ... OG may have a function to retrieve that list I dunno.

Once you have a list of UIDs use Devel and dpm($form); the form object and you can simply unset() the #options values for UIDs that dont belong in the OG group. Here's a similar thing I did for limiting to a taxonomy term_reference field to a given level of a nested taxonomy.

If you're paranoid you can also append your own validator function to the form_submit function and cross check that valid UIDs (members in the OG group) are being saved .... but I dont usually bother to do that for intranet sites (I have "trusted" users / staff members ... not joe blow public).

Sample code doing basically the same thing for a taxonomy term reference field.

 * Implements hook_form_alter().
function eap_student_videos_form_alter(&$form, &$form_state, $form_id) {
    switch ($form_id) {
      // Field specific overrides.
      case 'eap_studentvideos_node_form':
          $form['field_eap_video_country']['#after_build'][] = 'eap_country_term_limit_to_countries';

function _eap_region_tids() {
  return array(24,35,48,8,4);

function eap_country_term_limit_to_countries(&$element) {
    $options = $element[LANGUAGE_NONE]['#options'];
    $result = db_query('
        SELECT tth.tid, ttd.name AS term_name
        FROM taxonomy_term_hierarchy tth
        LEFT JOIN taxonomy_term_data ttd ON tth.tid = ttd.tid
        WHERE tth.parent IN  (:tids)
        ORDER BY 2 ASC
    ', array(':tids' => _eap_region_tids()));
    $country_tids = $result->fetchAllAssoc('tid');
    $country_tid_array = array_combine(array_keys($country_tids), array_keys($country_tids));
    $new_options = array_intersect_key($options, $country_tid_array);
    array_walk($new_options, function(&$value, &$key) { $value = str_replace('-','',$value); });
    // array_merge() destroys the array keys.
    $new_options = array('_none' => '- Select a value -') + $new_options;
    $element[LANGUAGE_NONE]['#options'] = $new_options;
    return $element;
  • Thanks for the tip. I'll try this today and let you know if it works for me.
    – mlibjh
    Jul 27, 2012 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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