我已经构建了一组节点。在通过node_save()
运行后,我找回了nid
,我可以导航到该节点的页面,但它们是空的。 (没有数据显示的任何字段。)Drupal-6:为什么这个节点不会保存?
当我去到编辑网址为节点,我收到此错误信息:
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'Bout_node_form' was given in /home/odp/public_html/includes/form.inc on line 367.
这里是一个节点,我尝试print_r()
保存:
stdClass Object
(
[type] => Bout
[name] => Gary Oak
[title] => Bout - 0
[promote] => 1
[comment] => 2
[revision] =>
[format] => 0
[status] => 0
[field_weapon] => Array
(
[0] => Array
(
[value] => foil
)
)
[field_fencer] => Array
(
[0] => Array
(
[uid] => 3
)
)
[field_touches_scored] => Array
(
[0] => Array
(
[value] => 4
)
)
[field_meet] => Array
(
[0] => Array
(
[nid] => Drew
)
)
[field_round] => Array
(
[0] => Array
(
[value] => 1
)
)
[field_legacy_bout] => Array
(
[0] => Array
(
[value] => no
)
)
[teaser] =>
[uid] => 1
[created] => 1262732370
[validated] => 1
)
这些节点已全部运行,虽然node_validate()
,想必会已经引起一些错误。此外,此节点缺少所需的分类,但这也不会导致任何错误消息。
这是node_validate()
如何被调用:
function preview_validate($form, &$form_state) {
$nodes_to_save = construct_nodes();
foreach ($nodes_to_save as $node) {
node_validate($node, $form);
if ($errors = form_get_errors()) {
form_set_error('', t('Validation error. No nodes saved.'));
}
}
$_SESSION[CONSTRUCTED_KEY] = $nodes_to_save;
}
这是错误是从哪里来的,在核心文件includes/form.inc
:
// If $callback was returned by a hook_forms() implementation, call it.
// Otherwise, call the function named after the form id.
$form = call_user_func_array(isset($callback) ? $callback : $form_id, $args);
节点在node
表显示,但不是content_type_bout
表。
这是construct_nodes()函数:
function construct_nodes() {
global $user;
$file = unserialize($_SESSION[FILE_KEY]);
$count = 0; // how many nodes have been created?
$success = TRUE; // have all the nodes thus far validated?
foreach ($file->parsed as $node) {
$odp = new StdClass();
$odp->type = $_SESSION[NODE_TYPE_KEY];
if (! in_array('name', $file->matched_keys)) {
$odp->name = $user->name;
}
if (! in_array('title', $file->matched_keys)) {
$odp->title = sprintf("%s - %s", $_SESSION[NODE_TYPE_KEY], $count);
}
$node_type_default = variable_get('node_options_'. $_SESSION[NODE_TYPE_KEY], array('status', 'promote')); //copied from blogapi module
$odp->promote = in_array('promote', $node_type_default);
$odp->comment = variable_get('comment_'. $_SESSION[NODE_TYPE_KEY], 2);
$odp->revision = in_array('revision', $node_type_default);
$odp->format = FILTER_FORMAT_DEFAULT;
$odp->status = CTN_DEFAULT_PUBLISHED;
// this makes the assumption that the field arrays will always have only one item
// doesn't handle taxonomy
foreach ($node as $field => $value) { // $field => value: [Touches scored] => 5
$node_key = $file->matched_keys[$field]; // $node_key will be something like: "field_meet" or "vid:4"
$vid = vidOfTaxKey($node_key);
if ($vid == NULL) {
$valTypes = $_SESSION[SAMPLE_NODE_KEY]->$node_key; // like: [0] => Array ([uid] => 3)
$valType = array_keys($valTypes[0]);
$odp->$node_key = array(array($valType[0] => $value));
}
}
$to_save[] = $odp;
$count++;
unset($submitted_odp);
}
return $to_save;
}
bout
是CCK-定义的内容类型。我相信,使用人名“Bout”代替内部代码名称bout
是错误的来源。
你是怎么称之为node_validate() – streetparade 2010-01-05 23:16:24
请显示第367行是 – streetparade 2010-01-05 23:18:27
以上澄清 – 2010-01-06 00:23:36