向内容管理员添加新的自定义字段/列

时间:2012-01-26 18:01:37

标签: php drupal-7 admin

我已经能够在表格的底部添加一个元素。虽然我不确定你是如何将一个色彩添加到桌子的主体中的?

function seven_form_alter(&$form, &$form_state, $form_id) {
        drupal_set_message("Form ID is : " . $form_id);

        //get node_admin_content
        //$nodeAdmin = drupal_get_form("node_admin_content");


          // Add a checkbox to registration form about agreeing to terms of use.
  $form['node_admin_content']['poland'] = array(
    '#type' => 'checkbox', 
    '#title' => t("I agree with the website's terms and conditions."), 
    '#required' => TRUE,
  );

}

1 个答案:

答案 0 :(得分:1)

该表由node_admin_nodes()构建,并且有一个很好的渲染数组,因此您可以覆盖它:

// Get the header array and add your new column header
$header = $form['admin']['nodes']['#header'];
$header['new_column'] = array('data' => 'New Col Header');
$form['admin']['nodes']['#header'] = $header;

// Get the table rows and add your new column to each.
// The function used to output the table depends on the user permissions
// so you need to check what type of object is being rendered.
if (isset($form['admin']['nodes']['#options'])) {
  $row_key = '#options';
}
else {
  $row_key = '#rows';
}

$rows = $form['admin']['nodes'][$row_key];

foreach ($rows as $nid => $row) {
  $form['admin']['nodes'][$row_key][$nid]['new_column'] = array('data' => 'Text');
}