You are here

function og_field_audience_default_value in Organic groups 7

Default value function for OG audience fields.

Set the default from the URL context. This works even if the widget is not shown, e.g. due to restricted field access.

See also

og_og_fields_info()

2 string references to 'og_field_audience_default_value'
og_og_fields_info in ./og.module
Implements hook_og_fields_info().
og_update_7102 in ./og.install
Add default value function to all audience field instances.

File

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

Code

function og_field_audience_default_value($entity_type, $entity, $field, $instance, $langcode) {
  $gids = og_get_context_by_url();
  if (!$gids) {
    return;
  }
  $items = array();
  $groups = og_load_multiple($gids);
  foreach ($groups as $gid => $group) {

    // Check access to group, and user is a group member.
    if ($group
      ->access() && og_is_member($gid)) {
      $items[] = array(
        'gid' => $gid,
      );
    }
  }
  return $items;
}