You are here

function theme_follow_links_form in Follow 5

Same name and namespace in other branches
  1. 6 follow.module \theme_follow_links_form()
  2. 7.2 follow.module \theme_follow_links_form()
  3. 7 follow.module \theme_follow_links_form()

Theme the drag-and-drop form.

Arranges records in a table, and adds the css and js for draggable sorting.

File

./follow.module, line 521
Allows users to add links to their social network profiles.

Code

function theme_follow_links_form($form) {
  $rows = array();
  $disabled_rows = array();
  foreach (element_children($form['follow_links']) as $key) {
    $row = array();
    if (isset($form['follow_links'][$key]['weight'])) {
      $row[] = drupal_render($form['follow_links'][$key]['lid']) . drupal_render($form['follow_links'][$key]['name']);
      $row[] = drupal_render($form['follow_links'][$key]['url']);
      if (user_access('change follow link titles')) {
        $row[] = drupal_render($form['follow_links'][$key]['title']);
      }

      // Now, render the weight row.
      $form['follow_links'][$key]['weight']['#attributes']['class'][] = 'follow-links-weight';
      $row[] = drupal_render($form['follow_links'][$key]['weight']);

      // Add the new row to our collection of rows, and give it the 'draggable' class.
      $rows[] = array(
        'data' => $row,
        'class' => array(
          'draggable',
        ),
      );
    }
    else {
      $disabled_rows[] = array(
        drupal_render($form['follow_links'][$key]['name']),
        drupal_render($form['follow_links'][$key]['url']),
      );
    }
  }

  // Render a list of header titles, and our array of rows, into a table.
  $header = array(
    t('Name'),
    t('URL'),
  );
  if (user_access('change follow link titles')) {
    $header[] = t('Customized Name');
  }
  $header[] = t('Weight');
  $disabled_header = array(
    t('Name'),
    t('URL'),
  );
  $output = '';
  if (count($rows)) {
    $output .= theme('table', $header, $rows, array(
      'id' => 'follow-links-weighted-form',
    ));
  }
  if (count($disabled_rows)) {
    $output .= theme('table', $disabled_header, $disabled_rows);
  }
  $output .= drupal_render($form);
  return $output;
}