You are here

function theme_user_badges_userweight_form in User Badges 7

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

Form theming function

File

./user_badges.module, line 514
@brief User Badges module file

Code

function theme_user_badges_userweight_form($variables) {
  $form = $variables['form'];
  $output = '';

  // Loop through the array items in the name array to get all the bids for our listed badges.
  if (isset($form['name']) && is_array($form['name'])) {
    foreach (element_children($form['name']) as $key) {

      //We only want bids as values of $key
      if (!is_numeric($key)) {
        continue;
      }

      // Create the rows array for the table theme.
      $row = array();
      $row[] = drupal_render($form['name'][$key]);
      $row[] = drupal_render($form['badge'][$key]);
      $row[] = drupal_render($form['weight'][$key]);

      //Add the draggable class to this row
      $rows[] = array(
        'data' => $row,
        'class' => array(
          'draggable',
        ),
        '#weight' => $form['weight'][$key]['#value'],
      );
    }

    // Sort the rows by their weights.
    usort($rows, 'element_sort');

    // Add the submit button.
    $row = array();
    $row[] = '';
    $row[] = drupal_render($form['submit']);
    $row[] = '';
    $rows[] = $row;
  }
  else {
    $rows[] = array(
      array(
        'data' => t('No badges available.'),
        'colspan' => '3',
      ),
    );
  }

  // This makes the table draggable.
  drupal_add_tabledrag('user_badges_userweight', 'order', 'sibling', 'user_badges_userweight_element');

  // Theme all that we have processed so far into a table.
  $output .= theme('table', array(
    'header' => $form['header']['#value'],
    'rows' => $rows,
    'attributes' => array(
      'id' => 'user_badges_userweight',
    ),
  ));

  // Render any remaining form elements.
  $output .= drupal_render_children($form);
  return $output;
}