开发者

Drupal dragable rows for module admin form - edit/delete links not visible

I have a simple module I'm building with dragable rows, and it's working except that the edit/delete links I had for each row before are now hidden along with the weight select (which I know is supposed to be hidden). It's putting the edit/delete links in the same hidden td as the weight. There is something that I'm missing in my code, but I just can't see it. The form:

function contestwinners_admin_form() {
  $winners = _contestwinners_load_winners(NULL, TRUE);
  $path = drupal_get_path('module', 'contestwinners') .'/';
  $form = array();
  $form['#tree'] = TRUE;
  foreach ($winners as $winner) {
    $form['winners'][$winner['crid']]['#winner'] = $winner;

    $form['winners'][$winner['crid']]['edit'] = array(
      '#type' => 'image_button',
      '#title' => t('Edit winner'),
      '#src' => $path .'text-editor.png',
      '#submit' => array('contestwinners_admin_edit_button'),
      '#crid' => $winner['crid'],
    );
    $form['winners'][$winner['crid']]['delete'] = array(
      '#type' => 'image_button',
      '#title' => t('Delete winner'),
      '#src' => $path .'edit-delete.png',
      '#submit' => array('contestwinners_admin_delete_button'),
      '#crid' => $winner['crid'],
    );

    // the "weight" field will be manipulated by the drag and drop table
    $form['winners'][$winner['crid']]['weight'] = array(
       '#type' => 'weight',
       '#delta' => 10,
       '#default_value' => $winner['weight'],
       '#attributes' => array('class' => 'weight'),
       );    

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save Changes'),
        );

  }
  return $form;
}

The themed function:

function theme_contestwinners_admin_form(&$form) {

  $headers = array(t('Name'), t('Description'), t('Actions'));

  $rows = array();

  if (!empty($form['winners'])) {
    foreach (element_children($form['winners']) as $crid) {
      $row = array();
      $winner = $form['winners'][$crid]['#winner'];
      $row[] = check_plain($winner['title']);
      $row[] = check_plain($winner['description']);
      $row[] = drupal_render($form['winners'][$crid]);

        // Add the weight field to the row
        // the Javascript to make our table drag and drop will end up hiding this cell
        $row[] = drupal_render($form['winners']['weight']);

        //Add the row to the array of rows
        $rows[] = array('data' => $row, 'class'=>'draggable');

    }
  }

  //print_r($rows);

  $link = l(t('Create a new winner'), 'admin/settings/contestwinners/add');

    $table_id = 'winners';

    // this function is what brings in the javascript to make our table drag-and-droppable
    drupal_add_tabledrag($table_id, 'order', 'sibling', 'weight');    

  $row = array();
  if (empty($rows)) {
    $row[] = array(
      'data' => t('No contest winners have been added yet. !url.', array('!url' => $link)),
      'colspan' => 4,
      'class'=>'draggable',
    );
  }else{
    $row[] = array(
      'data' => t('!url.', array('!url' => $link)),
      'colspan' => 4,
      'class'=>'draggable',
    );
  }

  $rows[] = $row;



    // over-write the 'my_items' form element with the markup generated from our table
    $form['winners'] = array(
        '#type' => 'markup',
        '#value' => theme('table', $headers, $rows, array('id' => $table_id)),
        '#weight' => '1',
        );


 // $output .= theme('table', $headers, $form);
  $output .= drupal_render($form);
  return $output;
}
开发者_运维百科

Edit to original post is below:

I sort of figured it out for now. I put them in separate td's until I figure out how to do it the other way. In function theme_contestwinners_admin_form() I put

function theme_contestwinners_admin_form(&$form) {
  $headers = array(t('Name'), t('Description'), t('Edit'), t('Delete'), t('Weight'));
  $rows = array();
  if (!empty($form['winners'])) {
    foreach (element_children($form['winners']) as $crid) {
      $row = array();
      $winner = $form['winners'][$crid]['#winner'];
      $row[] = check_plain($winner['title']);
      $row[] = check_plain($winner['description']);
      $row[] = drupal_render($form['winners'][$crid]['edit']);
      $row[] = drupal_render($form['winners'][$crid]['delete']);
      // Add the weight field to the row
      // the Javascript to make our table drag and drop will end up hiding this cell
      $row[] = drupal_render($form['winners'][$crid]['weight']);
        //Add the row to the array of rows
        $rows[] = array('data' => $row, 'class'=>'draggable');
    }
  }

  $link = l(t('Create a new winner'), 'admin/settings/contestwinners/add');

    $table_id = 'winners';

    // this function is what brings in the javascript to make our table drag-and-droppable
    drupal_add_tabledrag($table_id, 'order', 'sibling', 'weight');    

  $row = array();
  if (empty($rows)) {
    $row[] = array(
      'data' => t('No contest winners have been added yet. !url.', array('!url' => $link)),
      'colspan' => 5,
      'class'=>'draggable',
    );
  }else{
    $row[] = array(
      'data' => t('!url.', array('!url' => $link)),
      'colspan' => 5,
      'class'=>'draggable',
    );
  }

  $rows[] = $row;
    // over-write the 'my_items' form element with the markup generated from our table
    $form['winners'] = array(
        '#type' => 'markup',
        '#value' => theme('table', $headers, $rows, array('id' => $table_id)),
        '#weight' => '1',
        );

    $output = '';
    $output .= drupal_render($form);
    return $output;
}


I sort of figured it out for now. I put them in separate td's until I figure out how to do it the other way. In function theme_contestwinners_admin_form() I put

function theme_contestwinners_admin_form(&$form) {
  $headers = array(t('Name'), t('Description'), t('Edit'), t('Delete'), t('Weight'));
  $rows = array();
  if (!empty($form['winners'])) {
    foreach (element_children($form['winners']) as $crid) {
      $row = array();
      $winner = $form['winners'][$crid]['#winner'];
      $row[] = check_plain($winner['title']);
      $row[] = check_plain($winner['description']);
      $row[] = drupal_render($form['winners'][$crid]['edit']);
      $row[] = drupal_render($form['winners'][$crid]['delete']);
      // Add the weight field to the row
      // the Javascript to make our table drag and drop will end up hiding this cell
      $row[] = drupal_render($form['winners'][$crid]['weight']);
        //Add the row to the array of rows
        $rows[] = array('data' => $row, 'class'=>'draggable');
    }
  }

  $link = l(t('Create a new winner'), 'admin/settings/contestwinners/add');

    $table_id = 'winners';

    // this function is what brings in the javascript to make our table drag-and-droppable
    drupal_add_tabledrag($table_id, 'order', 'sibling', 'weight');    

  $row = array();
  if (empty($rows)) {
    $row[] = array(
      'data' => t('No contest winners have been added yet. !url.', array('!url' => $link)),
      'colspan' => 5,
      'class'=>'draggable',
    );
  }else{
    $row[] = array(
      'data' => t('!url.', array('!url' => $link)),
      'colspan' => 5,
      'class'=>'draggable',
    );
  }

  $rows[] = $row;
    // over-write the 'my_items' form element with the markup generated from our table
    $form['winners'] = array(
        '#type' => 'markup',
        '#value' => theme('table', $headers, $rows, array('id' => $table_id)),
        '#weight' => '1',
        );

    $output = '';
    $output .= drupal_render($form);
    return $output;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜