You are here

function theme_scs_sortable_table in Simplenews Content Selection 7

Same name and namespace in other branches
  1. 8 scs.theme.inc \theme_scs_sortable_table()
  2. 7.2 scs.theme.inc \theme_scs_sortable_table()

Theme the node selection form

Parameters

$form Array The form structure ready to be rendered:

File

./scs.theme.inc, line 13
Select Drupal content to create a newsletter

Code

function theme_scs_sortable_table($form) {
  $form = $form['form'];
  $headers = array(
    t('Node title'),
    t('Weight'),
  );
  $rows = array();
  $nids = element_children($form['nodes']);

  // Fetch the titles for each nid
  $titles = db_select('node', 'n')
    ->fields('n', array(
    'nid',
    'title',
  ))
    ->condition('nid', array_values($nids))
    ->execute()
    ->fetchAllKeyed();
  foreach ($nids as $nid) {
    $row = array();
    $row[] = $titles[$nid];
    $row[] = drupal_render($form['nodes'][$nid]['weight']);
    $rows[] = array(
      'data' => $row,
      'class' => array(
        'draggable',
      ),
    );
  }
  $output = theme('table', array(
    'header' => $headers,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'scs-sort-nodes',
    ),
  ));
  $info = '';
  if (isset($form['scs_title']) && isset($form['scs_toc'])) {
    $info = drupal_render($form['scs_title']) . drupal_render($form['scs_toc']);
  }
  $output = $info . $output . drupal_render_children($form);
  drupal_add_tabledrag('scs-sort-nodes', 'order', 'sibling', 'node-weight');
  return $output;
}