You are here

function user_badges_edit_form in User Badges 6.2

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

Define the edit form for userbadges.

1 string reference to 'user_badges_edit_form'
user_badges_menu in ./user_badges.module
Implements hook_menu().

File

./user_badges.admin.inc, line 136
@brief User Badges admin functions

Code

function user_badges_edit_form($form_state, $bid = NULL) {

  // If we have been given an existing badge (bid) then get all the badge info into $edit.
  if (is_numeric($bid)) {
    $edit = db_fetch_object(db_query('SELECT * FROM {user_badges_badges} WHERE bid = %d', $bid));
    if (is_numeric($edit->bid)) {
      $form['bid'] = array(
        '#type' => 'value',
        '#value' => $edit->bid,
      );
    }
  }

  // Are we using a library image or an image URL?
  if (isset($edit) && valid_url($edit->image, TRUE)) {
    $imageurl = $edit->image;
    $libraryimage = '';
  }
  else {
    $libraryimage = $edit->image;
    $imageurl = '';
  }
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => isset($edit) ? $edit->name : '',
    '#size' => 40,
    '#maxlength' => 100,
    '#description' => t('Name for the badge. Will be displayed as a tooltip when rolling over the badge.'),
    '#required' => TRUE,
  );
  $form['imageurl'] = array(
    '#type' => 'textfield',
    '#title' => t('Image URL'),
    '#default_value' => $imageurl,
    '#size' => 60,
    '#maxlength' => 255,
    '#description' => t('The image URL for this badge. If you want to use an image from the user badges image library, select from the list below.'),
  );
  $form['weight'] = array(
    '#type' => 'textfield',
    '#title' => t('Weight'),
    '#size' => 4,
    '#maxlength' => 10,
    '#default_value' => isset($edit) ? $edit->weight : 0,
    '#description' => t('Lighter weighted items float to the top of lists. Heavier items go to the bottom. You must enter a number (negative values are allowed).'),
    '#required' => TRUE,
  );
  $form['href'] = array(
    '#type' => 'textfield',
    '#title' => t('Description URL'),
    '#size' => 60,
    '#maxlength' => 255,
    '#description' => t('You can specify here the link where your badge will redirect your user.
      This is useful for explanation pages about the badge, for instance. If you do not wish
      your badge to be clickable, please leave this field empty.') . '<br />' . '<u>' . t('Tips:') . '</u>' . '<ul>' . '<li>' . t('If you provide the full URL, it will be considered an external URL.') . '</li>' . '<li>' . t('If you provide only the path (e.g. "admin/content/node"), it is considered an
          internal link.') . '</li>' . '<li>' . t('Use %none to override a default link in the settings tab with no link for this badge.', array(
      '%none' => '<none>',
    )) . '</li>' . '</ul>',
    '#default_value' => $edit->href,
  );

  // Tokens help.
  if (module_exists('token')) {
    $form['token_help'] = array(
      '#title' => t('Replacement patterns'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['token_help']['help'] = array(
      '#value' => theme('token_help', array(
        'userbadge',
        'user',
      )),
    );
  }
  else {
    $form['token_help'] = array(
      '#title' => t('Replacement patterns'),
      '#type' => 'fieldset',
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['token_help']['help'] = array(
      // Ignore Coder flag on the link.
      '#value' => t('Install the !link module if you want this URL to include dynamic elements such as badge ID numbers.', array(
        '!link' => l('Token', 'http://drupal.org/project/token', array(
          'absolute' => TRUE,
        )),
      )),
    );
  }
  if (module_exists('taxonomy')) {
    if (variable_get('user_badges_vid', '')) {
      $form['tid'] = taxonomy_form(variable_get('user_badges_vid', ''), $edit->tid);

      // Taxonomy sets the weight to -15, so we should get rid of it to preserve the ordering.
      unset($form['tid']['#weight']);
      $form['tid']['#multiple'] = FALSE;
    }
    else {
      $form['tid']['help'] = array(
        '#value' => t('Activate the taxonomy module if you want to associate badges with taxonomy terms.'),
      );
    }
  }
  $form['unhideable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Cannot be Hidden'),
    '#default_value' => $edit->unhideable,
    '#description' => t('If this is set, the badge cannot be hidden by being moved down in weight. It will always show up.'),
  );
  $form['fixedweight'] = array(
    '#type' => 'checkbox',
    '#title' => t('Fixed Weight'),
    '#default_value' => $edit->fixedweight,
    '#description' => t('If this is set, the badge cannot have a user assigned weight, regardless of settings.'),
  );
  $form['doesnotcounttolimit'] = array(
    '#type' => 'checkbox',
    '#title' => t('Does Not Count to Limit'),
    '#default_value' => $edit->doesnotcounttolimit,
    '#description' => t('If this is set, the badge does not count towards the limit for number of badges to display per user.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  $selects = array(
    '' => t('Use the image URL above instead of a library image.'),
  ) + user_badges_image_selects();
  if (count($selects)) {
    $form['image'] = array(
      '#type' => 'radios',
      '#title' => t('Image Library'),
      '#default_value' => $libraryimage,
      '#options' => $selects,
      '#description' => t('If you have not entered an image URL above, you can select an image from this user badges image library to associate with this badge. You can upload additional images to the library under the <a href="@url">images</a> tab.', array(
        '@url' => url("admin/user/user_badges/images"),
      )),
    );
  }
  else {
    $form['noimages'] = array(
      '#type' => 'item',
      '#title' => t('Image'),
      '#value' => t('No badge images uploaded.'),
      '#description' => t('You can enter an image URL directly above, but if you want to instead upload your image to the user badges image library, use <a href="@upload_link">this link</a>. Note that private download is incompatible with this library and should use direct URL entry instead.', array(
        '@upload_link' => url("admin/user/user_badges/images"),
      )),
    );
  }
  $form['submit2'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}