You are here

function group_membership_form in Group 7

Generates the group membership editing form.

1 string reference to 'group_membership_form'
GroupMembershipUIController::hook_forms in classes/group_membership.ui_controller.inc
Provides definitions for implementing hook_forms().

File

forms/group_membership.inc, line 10
Group membership editing UI.

Code

function group_membership_form($form, &$form_state, GroupMembership $group_membership, $op = 'edit') {
  $form['#entity_builders'][] = 'group_membership_restore_roles_eb';
  $group = group_load($group_membership->gid);
  $account = user_load($group_membership->uid);
  if ($op == 'edit') {
    $message = 'Edit membership for %user in %group';
    $replace = array(
      '%user' => format_username($account),
      '%group' => $group
        ->label(),
    );
    drupal_set_title(t($message, $replace), PASS_THROUGH);
  }

  // Only show the role selector if the current user can administer members.
  if (group_access('administer members', $group)) {
    $roles = array();
    foreach ($group
      ->getRoles(FALSE) as $group_role) {
      $roles[$group_role->name] = $group_role
        ->label();
    }
    $form['roles'] = array(
      '#title' => t('Group roles'),
      '#type' => 'checkboxes',
      '#options' => $roles,
      '#default_value' => $group_membership->roles,
    );
  }

  // Load fields based on group type.
  field_attach_form('group_membership', $group_membership, $form, $form_state, entity_language('group_membership', $group_membership));
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Edit membership'),
    '#weight' => 40,
  );
  return $form;
}