drupal-7 - drupal alter node编辑表单

标签 drupal-7 hook-form-alter

如何在创作信息发布选项部分下面的节点编辑表单中添加自定义配置区域?

最佳答案

您可以使用hook_form_FORM_ID_alter()
下面的例子:

function my_module_form_node_form_alter(&$form, $form_state) {
  // if you are targeting a specific content type then 
  // you can access the type:
  $type = $form['#node']->type;
  // Then
  if ($type == 'my_content_type') {
  //  use a contact settings for the sake of this example
   $form['contact'] = array(
    '#type' => 'fieldset', 
    '#title' => t('Contact settings'), 
    '#weight' => 100, 
    '#collapsible' => TRUE, 
    '#collapsed' => FALSE,
   );
   // add simple checkbox to the field set
   $form['contact']['approve'] = array(
     '#type' =>'checkbox', 
     '#title' => t('Contact me'),
   );
  } 
}

现在,为了存储数据,我鼓励您查看examples项目。它有许多带有大量文档的代码示例。
另外,请检查the Form API以获取有关不同类型的表单元素的更多信息。
希望这可以帮助。

关于drupal-7 - drupal alter node编辑表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13529636/

相关文章:

Drupal 7 - 以编程方式向节点添加自由标记

php - 如何在代码中获取分类术语的机器名称?

https - 如何使用 drupal_http_request 构造 https POST 请求?

php - 这些使用 db_or() 的 Drupal SQL 查询有什么问题?

drupal - 为什么我不能将字段移动到 Drupal 表单中的字段集中 - 无法获取当前值

forms - 如何在 Drupal 中隐藏用户编辑表单上的某些字段?

drupal - 在 form_alter 中提交操作后

seo - 打开我网站的 www 版本导致我首选的非 www 版本在 drupal 7 中被破坏