You are here

function user_badges_change_form in User Badges 7.4

Same name and namespace in other branches
  1. 6.2 user_badges.module \user_badges_change_form()
  2. 6 user_badges.module \user_badges_change_form()
  3. 7 user_badges.module \user_badges_change_form()
  4. 7.2 user_badges.module \user_badges_change_form()
  5. 7.3 user_badges.module \user_badges_change_form()

Form to change badges of a user.

1 string reference to 'user_badges_change_form'
user_badges_page in ./user_badges.module
Define the badges edit page.

File

./user_badges.module, line 678
Hooks and other stuff related to user badge.

Code

function user_badges_change_form($form, &$form_state, $account) {
  $form = array();
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $account->uid,
  );
  $form['add'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add Badges'),
    '#weight' => 3,
    '#tree' => TRUE,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  // Determine which selector type the user wants to use to
  // set badges from their settings
  // If the user wants to use the drop-down selector,
  // display that if there are records in the db.
  if (variable_get('user_badges_selector_type', 1) == 0) {

    // Display the drop-down only if we get any records.
    $options = user_badges_get_badges('select');

    // Initialize the $options array,
    // which will contain all the badges fetched from the db
    // Add a - None - option to the badge list as Drupal core
    // won't give it to us automatically because it is a multi select list!!
    $options[-1] = '- None -';

    // Add the drop-down multi select box to add badges.
    $form['add']['add_drop_down'] = array(
      '#type' => 'select',
      '#title' => t('New Badges'),
      '#options' => $options,
      '#multiple' => TRUE,
    );
  }
  else {
    for ($i = 1; $i <= 5; $i++) {

      // Add the autocomplete boxes to add badges.
      $form['add'][$i] = array(
        '#type' => 'textfield',
        '#title' => t('New Badge @number', array(
          '@number' => $i,
        )),
        '#size' => 40,
        '#maxlength' => 255,
        '#autocomplete_path' => 'entityreference/autocomplete/single/user_badge_badges/user/user/NULL',
      );
    }
  }
  $user_badges = user_badges_get_badges($account->uid);
  if (count($user_badges)) {
    $form['remove'] = array(
      '#type' => 'fieldset',
      '#title' => t('Remove Badges'),
      '#weight' => 5,
      '#tree' => TRUE,
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    foreach ($user_badges as $key => $user_badge) {
      $form['remove'][$key] = array(
        '#type' => 'checkbox',
        '#title' => check_plain($user_badge->name),
        '#return_value' => 1,
        '#default_value' => 0,
        '#description' => t('Tick to remove %badge_name from this user', array(
          '%badge_name' => check_plain($user_badge->name),
        )),
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update Badges'),
    '#weight' => 10,
  );
  return $form;
}