drupal:自定义内容类型字段#default_value不显示

时间:2010-12-05 18:07:37

标签: drupal

我正在学习drupal,正在开发一个创建自定义内容类型的模块。一切正常。我可以添加和更新自定义节点。唯一不起作用的是,当我编辑节点时,不会显示2个自定义字段的#default_value。这是我的hook_form:

function mymodule_form(&$node, $form_state) {
  $type = node_get_types('type', $node);
  $form['title'] = array(
        '#type' => 'textfield',
        '#title' => check_plain($type->title_label),
        '#required' => TRUE,
        '#default_value' => $node->title,
        '#weight' => -5,
    );
    $form['body'] = array(
    '#type' => 'textarea', 
    '#title' => check_plain($type->body_label), 
    '#rows' => 20, 
     '#default_value' => $node->body,
    '#required' => TRUE,
  );
  $form['other'] = array(
    '#type' => 'textfield', 
    '#title' => t('Other thingy'), 
    '#default_value' => $node->other, 
  );
  if ($node->type == 'chucky') {
    $form['other2'] = array(
        '#type' => 'textfield', 
        '#title' => t('Other thingy 2'), 
        '#default_value' => $node->other2, 
      );
  }
  return $form; 
}

所以2个自定义字段是other和other2,这些列在mymodule表中,我可以添加和更新它们的值。但它们不会在编辑表单中重新显示为默认值。

1 个答案:

答案 0 :(得分:0)

抱歉,我应该在我正在关注的教程中进一步阅读。显然,自定义字段不是节点对象的一部分,直到您使用hook_load()检索它们。现在工作正常。