开发者

Drupal-6: Why won't this node save?

开发者 https://www.devze.com 2022-12-15 18:25 出处:网络
I have constructed a set of nodes. After running them through node_save(), I get back an nid, and I can navigate to the page for that node, but they are empty. (No data is shown for any of the fields.

I have constructed a set of nodes. After running them through node_save(), I get back an nid, and I can navigate to the page for that node, but they are empty. (No data is shown for any of the fields.)

When I go to the edit url for that node, I get this error message:

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.

Here is the print_r() of one node I am t开发者_运维百科rying to save:

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
)

These nodes have all been run though node_validate(), and presumably that would have caught some errors. Also, this node is missing required taxonomy, but that isn't causing any error messages, either.

This is how node_validate() was called:

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;
}

This is where the error is coming from, in the core file 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);

The node shows up in the node table, but not the content_type_bout table.

This is the construct_nodes() function:

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 is a CCK-defined content type. Using the human name "Bout" for the type instead of the internal code name bout was, I believe, a source of error.


  1. where is this custom content type defined? in a custom module, or via Administer > Content > Content types > Add content type? is it defined at all? if not, then no wonder you get this error: how is Drupal supposed to know what this content type is composed of and how to render its view and edit forms? try defining it, either way.

  2. custom content (node) type names ([type] => Bout) must contain only lowercase letters, numbers, and underscores. try changing Bout to bout.

see also How do I create a node from a cron job in drupal? and http://drupal.org/node/178506#comment-895418 (the whole thread).


try this

<?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);
?>

note that you should change this to your needs


$node['type']='bout'; NOT $node['type']='Bout';

Confirm that you are not struck with simple caps problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号