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

发布于 2024-12-29 07:27:37 字数 563 浏览 2 评论 0原文

我已经能够将一个元素添加到表格底部。虽然我不确定你如何将列添加到表体中?

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,
  );

}

I've been able to add an element to the bottom of the table. Although I am unsure how you ADD a coloumn into the body of the table?

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,
  );

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山川志 2025-01-05 07:27:37

该表由 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');
}

The table is built by node_admin_nodes() and comes in a nice render array so you can override it:

// 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');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文