我构建了一组节点。通过node_save()
运行它们后,我返回nid
,我可以导航到该节点的页面,但它们是空的。 (没有显示任何字段的数据。)
当我转到该节点的编辑网址时,收到以下错误消息:
警告:call_user_func_array() [function.call-user-func-array]:首先 参数预计是有效的 回调,给出'Bout_node_form' 在 /home/odp/public_html/includes/form.inc 在第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
是错误的来源。
答案 0 :(得分:4)
这个自定义内容类型在哪里定义?在custom module中,或通过管理员>内容>内容类型>添加内容类型?它是否定义了?如果没有,那么难怪你得到这个错误:Drupal如何知道这个内容类型是由什么组成的,以及如何呈现它的视图和编辑表单?尝试定义它,无论哪种方式。
自定义内容(节点)类型名称([type] => Bout
)must contain only lowercase letters, numbers, and underscores。尝试将Bout
更改为bout
。
另见How do I create a node from a cron job in drupal?和http://drupal.org/node/178506#comment-895418(整个主题)。
答案 1 :(得分:0)
试试这个
<?php
$new_blognode = new stdClass();
$new_blognode->type = 'blog';
module_load_include('inc', 'node', 'node.pages');
$output .= drupal_get_form('blog_node_form', $new_blognode);
?>
请注意,您应该根据需要进行更改
答案 2 :(得分:0)
$节点[ '类型'] = '回合'; NOT $ node ['type'] ='Bout';
确认您没有遇到简单的大写问题。