function blogapi_submit_node in Blog API 7.2
Emulates node_form submission as services module does
Parameters
$new_node: Object, data to be submitted to node_form
$old_node: Object, old node data to be submitted to node_form. May be the same as $new_node, if it is node creation
Return value
bool|mixed TRUE if node was updated or $node->nid if $node was created
2 calls to blogapi_submit_node()
- blogapi_edit_post in ./
blogapi.module - Service allback for metaWeblog.editPost
- blogapi_new_post in ./
blogapi.module - Creates a new node. Utility function for backend modules.
File
- ./
blogapi.module, line 646 - Enable users to post using applications that support BlogAPIs.
Code
function blogapi_submit_node($new_node, $old_node) {
$is_new_node = empty($old_node->nid);
blogapi_status_error_check($new_node);
// Load the required includes for drupal_execute
module_load_include('inc', 'node', 'node.pages');
if (!$is_new_node) {
node_object_prepare($old_node);
module_invoke_all('blogapi_node_edit', $new_node);
}
else {
module_invoke_all('blogapi_node_create', $new_node);
}
// Setup form_state.
$form_state = array();
$form_state['values'] = (array) $new_node;
$form_state['values']['op'] = t('Save');
if (!$is_new_node) {
$form_state['node'] = $old_node;
}
drupal_form_submit($old_node->type . '_node_form', $form_state, $old_node);
if ($errors = form_get_errors()) {
return services_error(implode(" ", $errors), 406, array(
'form_errors' => $errors,
));
}
else {
watchdog('content', '@type: updated %title using Blog API.', array(
'@type' => $old_node->type,
'%title' => $new_node->title,
), WATCHDOG_NOTICE, l(t('view'), "node/{$old_node->nid}"));
return $is_new_node ? $form_state['nid'] : TRUE;
}
}