Drupal 7,根据接口验证节点



我创建了一个Web服务,它运行正常,我正在进行节点创建操作,它运行正确。我需要验证我即将保存的节点,就像在接口插入表单中验证一样

我试过

drupal_form_submit($nodeType . '_node_form', $form_state, (object) $node);

它不断给我错误,它的节点参考字段

你能建议其他方法来进行与编程创建的节点上的接口相同的验证吗?

节点参考字段上的错误为:

"field_ente:此条目不能引用。">

节点(6310(正确存在,如果我尝试执行node_save,则会正确保存

完整的功能如下

function my_ws_resource_create($field_nome = '', $field_cognome = '', $field_codice_fiscale = '', $field_data_di_nascita = '', $field_ente= '')
{
module_load_include('inc', 'node', 'node.pages');
global $user;
$nodeType = 'contatti';
$node = new stdClass();
$node->type = $nodeType;
$node->uid = $user->uid;
$node->status = 1;
$node->revision = 1;
$node->promote = 0;
$node->comment = 0;
node_object_prepare($node);
$node->field_cognome['und'][0]['value'] = $field_cognome;
$node->field_nome['und'][0]['value'] = $field_nome;
$node->field_codice_fiscale['und'][0]['cck_codicefiscale'] = $field_codice_fiscale;
$node->field_data_di_nascita['und'][0]['value'] = $field_data_di_nascita;
$node->field_categoria_contatto['und'][0]['tid'] = '66';

// $node->field_ente = array('und' => array(array('nid'=> $field_ente )));
// this field causes the error
$node->field_ente = array('und' => array(array('nid'=> '6310')));

$node->field_simplenews_term['it'][0]['tid'] = '13660';
$form_state = array();      
$form_state['values']['type'] = $nodeType;    
$form_state['values']['name'] = $user->name;    
$form_state['values']['status'] = 1;
$form_state['values']['promote'] = 1;
$form_state['values']['sticky'] = 0;
$form_state['values']['op'] = t('Save');
drupal_form_submit($nodeType . '_node_form', $form_state, (object) $node);
if ($errors = form_get_errors()) {
return services_error(implode(" ", $errors), 406, array('form_errors' => $errors));
}
return 'Creation successful';
}

我在以下方面取得了成功(删除$form_state并替换drupal_form_submit(:

if ($node = node_submit($node)) {
node_save($node);
// Success!
}
else {
// Fail :(
}

相关内容

  • 没有找到相关文章

最新更新