You are here

function og_field_audience_options in Organic groups 7

Get an array of allowed values for OG audience field.

Return value

Array keyed by "content groups" and "other groups".

1 call to og_field_audience_options()
og_field_widget_form in ./og.field.inc
Implements hook_field_widget_form().
1 string reference to 'og_field_audience_options'
og_invalidate_cache in ./og.module
Invalidate cache.

File

./og.field.inc, line 587
Field module functionality for the Organic groups module.

Code

function og_field_audience_options(&$opt_group = FALSE, $account = NULL) {
  $return =& drupal_static(__FUNCTION__, array());

  // If we already have the full list of all groups, immediately return.
  if (isset($return['other groups']) && isset($return['content groups'])) {
    return $return;
  }
  elseif (!$opt_group && isset($return['content groups'])) {
    return $return;
  }
  if (empty($account)) {
    global $user;
    $account = clone $user;
  }

  // Initialize values.
  $return = array(
    'content groups' => array(),
    'other groups' => array(),
  );
  $content_groups = og_get_entity_groups('user', $account);
  $return['content groups'] = $content_groups;

  // Only generate all other groups if needed (generally for admins only).
  if ($opt_group) {
    $all_groups = og_get_all_group();
    $return['other groups'] = array_diff($all_groups, $content_groups);
  }

  // Allow other modules to change the audience options. While it can be done
  // via hook_form_alter(), it will require other modules to know too much of
  // the internal work.
  drupal_alter('og_audience_options', $return, $opt_group, $account);
  return $return;
}