drupal:自定义内容类型字段#default_value不显示
问题描述:
我在学习drupal,在创建自定义内容类型的模块上工作。一切正常。我可以添加和更新自定义节点。唯一不起作用的是当我编辑节点时,2个自定义字段的#default_value不显示。这里是我的hook_form:drupal:自定义内容类型字段#default_value不显示
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个自定义字段等和其它2,那些列在表mymodule中,我可以添加和更新它们的值。但是它们不会被重新显示为编辑表单中的默认值。
答
对不起,我应该在我正在关注的教程中进一步阅读。显然,自定义字段不是节点对象的一部分,除非您使用hook_load()检索它们。现在工作正常。