开发者

I want to call drupal_execute() for cck fields (DateTime user_reference) but it doesn't save anything in DB

开发者 https://www.devze.com 2023-01-21 10:58 出处:网络
I have a content type as a todo list element. It has some cck fields like deadline (in DateTime format) and assigned_user (a user reference field). I want to use function drupal_execute to create a su

I have a content type as a todo list element. It has some cck fields like deadline (in DateTime format) and assigned_user (a user reference field). I want to use function drupal_execute to create a such node programmatically, but after a full of errors like

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'views_access' was given in ..includes/menu.inc on line 454.

and creating the node, its cck values are NULL. this is my code

    $form_state = array();
$form_state['values'] = array(
    'title' => $title,
    'body' => $description,
    'name' => $GLOBALS['user']->name,
    'op' => t('Save'),
    'field_deadline' => array(
                0=> array('value'=>array('month'=>1,
                            'day'=>1,
                            'year'=>2011,
                            'hour'=> 1,
                            'minute'=> 1
                            ))      
            ),
    'field_notification_time' => array(
                0=> array('value'=>array('month'=>10,
                            'day'=>24,
                            'year'=>2010,
                            'hour'=> 0,
                            'minute'=> 24
                            ))      
            ),
    'field_assign_user' => array(
                0=> array(
                    'uid' => array( 'uid'=> 'user1')
                    )
            ),
);

$node = (object) array( 'type' => 'todo_element'); module_load_include('inc', 开发者_开发百科'node', 'node.pages');drupal_execute('todo_element_node_form', $form_state, $node);


you don't need to use drupal_execute. You can create your node object as you want and at the and you invoke:

$node = node_submit($node);
node_save($node);

node save then will call CCK to ask to save the field correctly in the DB.

0

精彩评论

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