I'm creating a module where I'm combining nodequeue with Views Bulk Operations, and as part of that, I need to modify the subqueue edit form. What I need to do is change the node Title field to a textfield, and add two other textfields to it. The data from these forms are pulled from a custom table, and I add a submit function to the form so the custom table is updated when the form is changed.

The problem I'm having is that the Title field is not being displayed properly. It's being combined with the Author field for some reason instead of being displayed as a separate field (see attached image).

First, here is my form alter function:

function feature_package_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'nodequeue_arrange_subqueue_form':
      // get extra information from feature_package_item table
      $sqid = $form['#subqueue']['sqid'];
      
      $sql = "SELECT * FROM feature_package_item WHERE sqid = %d";
      $result = db_query($sql, $sqid);
      while ($item = db_fetch_object($result)) {
        
        $form[$item->nid]['item_title'] = array(
          '#default_value' => $item->title,
          '#type' => 'textfield',
          '#size' => 10,
          '#maxlength' => 50,
        ); 
        $form[$item->nid]['item_tagline'] = array(
          '#default_value' => $item->tagline,
          '#type' => 'textfield',
          '#size' => 10,
          '#maxlength' => 50,
        );
        $form[$item->nid]['item_label'] = array(
          '#default_value' => $item->label,
          '#type' => 'textfield',
          '#size' => 10,
          '#maxlength' => 50,          
        );
        $form['#submit'][] = 'feature_package_item_submit';
      }
      break;
  }
}

And here is my overridden theme function for the form:

function tony_nodequeue_arrange_subqueue_form($form) {
  $output = '';
  
  $subqueue = $form['#subqueue'];

  // get css to hide some of the help text if javascript is disabled
  drupal_add_css(drupal_get_path('module', 'nodequeue') .'/nodequeue.css');

  // TODO: Would be nice to expose qid, sqid, reference as classes for more custom theming :).
  // TODO: Create unique ID to make multiple tabledrag forms on a page possible
  drupal_add_tabledrag('nodequeue-dragdrop', 'order', 'sibling', 'node-position');
  drupal_add_js(drupal_get_path('module', 'nodequeue') .'/nodequeue_dragdrop.js');

  drupal_add_js(array('nodequeue' => array('reverse' => (bool) $form['#queue']['reverse'])), 'setting');

  // render form as table rows
  $rows = array();
  $counter = 1;
  foreach (element_children($form) as $key) {
    if (isset($form[$key]['title'])) {
      $row = array();

  //$row[] = drupal_render($form[$key]['title']);
      $row[] = drupal_render($form[$key]['item_title']);
      $row[] = drupal_render($form[$key]['author']);
      $row[] = drupal_render($form[$key]['date']);
      $row[] = drupal_render($form[$key]['position']);
      $row[] = drupal_render($form[$key]['edit']);
      $row[] = drupal_render($form[$key]['remove']);
      $row[] = array(
        'data' => $counter,
        'class' => 'position'
      );
      $row[] = drupal_render($form[$key]['item_tagline']);
      $row[] = drupal_render($form[$key]['item_label']);

      $rows[] = array(
        'data'  => $row,
        'class' => 'draggable',
      );
    }
    // unset title so it doesn't get rendered later
    unset($form[$key]['title']);
    
    $counter++;
  }
  if (empty($rows)) {
    $rows[] = array(array('data' => t('No items in this package.'), 'colspan' => 7));
  }

  // render the main nodequeue table
  $caption = 'Feature Package Items';
  $header = array(t('Title'), t('Author'), t('Post Date'), t('Position'), array('data' => t('Operations'), 'colspan' => 2), t('Position'), t('Item Tagline'),  t('Item Label'));
  //$header = array(t('Title'), t('Author'), t('Post Date'), t('Position'), array('data' => t('Operations'), 'colspan' => 2), t('Position')); 
  $output .= theme('table', $header, $rows, array('id' => 'nodequeue-dragdrop', 'class' => 'nodequeue-dragdrop'), $caption);

  // Don't show the autocomplete field for adding a node to the table
  // since items are added to the feature package with VBO above the form
    unset($form['add']);
     
  // render the autocomplete field for adding a node to the table
  /*
  $output .= '<div class="container-inline">';
  $output .= drupal_render($form['add']['nid']);
  $output .= drupal_render($form['add']['submit']);
  $output .= '</div>'; */

  // render the remaining form elements
  $output .= drupal_render($form);

  return $output;
}

I played with the HTML a bit, and it looks like the problem is that the form item gets added as a <div>, and that screws up the layout. Am I seeing this correct and that's what needs to be changed? Or is there something else I need to change?

Thanks.

CommentFileSizeAuthor
subqueue_form_with_mods.jpg39.59 KBwonder95
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wonder95’s picture

Status: Active » Fixed

OK, got this taken care of, and in quite a painless way. The display problems are caused by the negative values for the margin and padding settings for the tabledrag handle, which cause the fields to combine together. Since the handle is simply added to the first column on the page, I just added an empty column at the beginning of the table in my override of theme_nodequeue_arrange_subqueue_form. Thus, the tabledrag handle gets put in the empty column by itself, and everything lines up nice and neat.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.