You are here

function og_register_field_attach_form in Organic groups 7.2

Implements hook_field_attach_form().

Mark the group-audience fields as ones that are used i registration. This is used to later on make sure the user is registered according to the allowed permissions (i.e. with or without administrator approval).

File

og_register/og_register.module, line 88
Allow subscribing to groups during the user registration.

Code

function og_register_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
  global $user;
  if ($user->uid || $entity_type != 'user') {
    return;
  }
  if (!module_exists('og_ui')) {
    return;
  }
  if (!($fields = og_get_group_audience_fields())) {
    return;
  }
  foreach (array_keys($fields) as $field_name) {
    if (empty($form[$field_name])) {
      continue;
    }
    $form[$field_name]['#element_validate'][] = 'og_register_og_membership_state_validate';
  }
}