2010-12-05 1 views
1

J'ai un module simple que je construis avec des rangées pouvant être déplacées, et qui fonctionne sauf que les liens d'édition/suppression que j'avais pour chaque ligne avant sont maintenant cachés avec le poids choisi (que je sais est censé être caché). C'est mettre les liens edit/delete dans le même td caché que le poids. Il y a quelque chose qui me manque dans mon code, mais je ne peux pas le voir. La forme:Drupal lignes dragables pour module admin formulaire - modifier/supprimer des liens non visibles

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; 
} 

La fonction sur le thème:

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; 
} 

Modifier à la publication dorigine est ci-dessous:

je sorte de figured it out pour l'instant. Je les ai mis dans des td séparés jusqu'à ce que je trouve comment faire dans l'autre sens. En fonction theme_contestwinners_admin_form() Je mis

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

Je me suis débrouillé pour le moment. Je les ai mis dans des td séparés jusqu'à ce que je trouve comment faire dans l'autre sens. Voir mes modifications dans mon message original. Je ne comprends pas pourquoi ce site ne vous laissera pas ajouter plus de caractères pour les commentaires aux articles ???? – EricP

Répondre

0

Je me suis en quelque sorte dehors pour l'instant. Je les ai mis dans des td séparés jusqu'à ce que je trouve comment faire dans l'autre sens. Dans la fonction theme_contestwinners_admin_form() je mets

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; 
} 
Questions connexes