type)) { og_register_create_fields($info->type); } } /** * Implement hook_node_type_update(). */ function og_register_node_type_update($info) { if (og_is_group_type('node', $info->type)) { og_register_create_fields($info->type); } } /** * Implement hook_form_FORM_ID_alter(). * * Get all the groups that should appear in the user registration, and show them. */ function og_register_form_user_register_form_alter(&$form, $form_state) { if ($groups = og_register_get_groups()) { $form['og_register'] = array( '#type' => 'fieldset', '#title' => t('Groups'), ); $form['og_register']['og_register_groups'] = array( '#type' => 'og_audience', '#title' => t('Subscribe to group'), '#includes' => array('content groups' => $groups), '#description' => t('Select the groups you wish to subscribe to.'), ); // Add own submit handler. $form['#submit'][] = 'og_register_register_submit'; } } /** * Implement og_get_fields(). */ function og_register_og_get_fields() { $items['og_register'] = array( 'type' => array('group'), 'description' => t('Add organic groups register field group types.'), 'field' => array( 'field_name' => 'og_register', 'type' => 'list_boolean', 'cardinality' => 1, 'settings' => array('allowed_values' => implode("\r\n", array('0|Do not show on registration page', '1|Show on registration page')), 'allowed_values_function' => ''), ), 'instance' => array( 'label' => t('Groups register'), // FIXME: Widget type doesn't work 'widget_type' => 'options_onoff', 'display' => array( 'full' => array( 'label' => 'above', 'type' => 'options_onoff', ), 'teaser' => array( 'label' => 'above', 'type' => 'options_onoff', ), ), ), ); return $items; } /** * Submit handler for the registration form. */ function og_register_register_submit($form, &$form_state) { if (!empty($form_state['values']['og_audience']) && ($nids = array_filter($form_state['values']['og_audience']))) { $groups = array(); foreach ($nids as $nid) { $groups[] = array('gid' => $nid); } og_subscribe_user($groups); } } /** * Get all the groups node IDs that should appear in the user registration. */ function og_register_get_groups($count = FIELD_QUERY_NO_LIMIT, &$cursor = 0) { $nids = array(); // Get all the group node IDs. if (($field = field_info_field(OG_REGISTER_FIELD)) && $result = field_attach_query($field['id'], array(), array('limit' => $count, 'cursor' => $cursor))) { foreach ($result['node'] as $value) { $nids[$value->nid] = $value->nid; } } return $nids; }