function commons_bw_partial_node_form_submit in Drupal Commons 7.3
Submit handler; Create a node from the partial node form.
File
- modules/
commons/ commons_bw/ commons_bw.module, line 306
Code
function commons_bw_partial_node_form_submit($form, $form_state) {
$node = $form['#entity'];
node_submit($node);
// Mark the node as created with the partial form
$node->partial_node_form = TRUE;
field_attach_submit('node', $node, $form, $form_state);
$wrapper = entity_metadata_wrapper('node', $node);
// If the node has a body and doesn't has a title, create a title from the
// body.
if ((empty($wrapper->title_field) || !$wrapper->title_field
->value()) && empty($node->title)) {
if (!empty($wrapper->body) && $wrapper->body
->value()) {
$title = htmlspecialchars_decode($wrapper->body->value
->value());
// Strip tags and whitespaces.
$title = preg_replace('/[\\t\\n\\r\\0\\x0B]/', '', strip_tags($title));
// Shorten the title.
$node->title = truncate_utf8($title, 30, TRUE, TRUE);
}
}
// Set the group audience.
if (!empty($form_state['group_id'])) {
$wrapper->{OG_AUDIENCE_FIELD}
->set(array(
$form_state['group_id'],
));
}
$node->form_state = $form_state;
$wrapper
->save();
// Notify about the node creation.
$arguments = array(
'@type' => node_type_get_name($node),
'%title' => $node->title,
);
drupal_set_message(t('@type %title has been created.', $arguments));
}