You are here

function og_ui_add_users in Organic groups 7

Same name and namespace in other branches
  1. 7.2 og_ui/og_ui.admin.inc \og_ui_add_users()

Add users to group form.

1 string reference to 'og_ui_add_users'
og_ui_menu in og_ui/og_ui.module
Implements hook_menu().

File

og_ui/og_ui.admin.inc, line 65
Admin settings for Organic groups module.

Code

function og_ui_add_users($form, &$form_state, $entity_type, $etid) {
  og_set_breadcrumb($entity_type, $etid, array(
    l(t('Group'), "{$entity_type}/{$etid}/group"),
  ));
  if ($group = og_get_group($entity_type, $etid)) {
    $label = og_label($group->gid);
    $form['group'] = array(
      '#type' => 'value',
      '#value' => $group,
    );
    $form['og_user'] = array(
      '#type' => 'fieldset',
      '#title' => t('Add a group member to %group', array(
        '%group' => $label,
      )),
    );
    $form['og_user']['og_add_user'] = array(
      '#type' => 'textfield',
      '#title' => t('User name'),
      '#autocomplete_path' => 'user/autocomplete',
      '#required' => TRUE,
    );
    $form['og_user']['og_add_user_state'] = array(
      '#type' => 'select',
      '#title' => t('Membership state'),
      '#options' => og_group_content_states(),
      '#description' => t('Select the state of the membership.'),
    );
    $options = array();
    foreach (entity_load('og_membership_type') as $type) {
      $options[$type->name] = check_plain($type->description);
    }
    $form['og_user']['og_add_user_membership_type'] = array(
      '#type' => 'select',
      '#title' => t('Membership type'),
      '#options' => $options,
      '#default_value' => 'OG_MEMBERSHIP_TYPE_DEFAULT',
      '#description' => t('Select the group membership type of the membership.'),
      '#ajax' => array(
        'callback' => 'og_ui_admin_add_user_ajax_callback',
        'wrapper' => 'og-ui-membership-type',
      ),
    );

    // Add group membership form.
    $type = !empty($form_state['values']['og_add_user_membership_type']) ? $form_state['values']['og_add_user_membership_type'] : OG_MEMBERSHIP_TYPE_DEFAULT;
    $dummy_entity = og_membership_create(0, 'user', 0, array(
      'type' => $type,
    ));
    $form['membership_fields'] = array(
      '#prefix' => '<div id="og-ui-membership-type">',
      '#suffix' => '</div>',
      '#tree' => TRUE,
      '#parents' => array(
        'membership_fields',
      ),
    );
    field_attach_form('og_membership', $dummy_entity, $form['membership_fields'], $form_state);
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Add users'),
    );
    return $form;
  }

  // Not a valid group node.
  drupal_not_found();
}