2010-12-05 38 views
1

我有一个简单的模块,我用可拖动的行建设,它的工作原理除了我以前每行的编辑/删除链接现在隐藏与重量选择(我知道应该隐藏)。它将编辑/删除链接放置在与重量相同的隐藏td中。我的代码中缺少一些东西,但我无法看到它。 形式:Drupal dragable行模块管理窗体 - 编辑/删除链接不可见

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

的主题功能:

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

编辑到原来的职位低于:

我有点理解了它现在。我把它们放在单独的td中,直到我找出如何以其他方式来完成它。 在功能theme_contestwinners_admin_form()我把

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

我有点想通了。我把它们放在单独的td中,直到我找出如何以其他方式来完成它。在我原来的帖子中查看我的编辑。我不明白为什么这个网站不会让你添加更多角色评论的帖子???? – EricP 2010-12-08 13:24:33

回答

0

我有点理解了它现在。我把它们放在单独的td中,直到我找出如何以其他方式来完成它。在功能theme_contestwinners_admin_form()我把

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; 
} 
相关问题