function oa_core_create_node in Open Atrium Core 7.2
Create a new content node within a space/section
Parameters
string $bundle name of node bundle to create:
object $context an optional code to copy space/section from: if not specified, current Session space/section context is used
Return value
object $wrapper entity metadata wrapper around node
NOTE: The created node is NOT SAVED. You need to use: $wrapper = oa_core_create_node(...); $wrapper->save(); to actually save the created node. This allows you to set other wrapper fields before saving
File
- includes/
oa_core.util.inc, line 729 - Code for Utility functions for OpenAtrium spaces
Code
function oa_core_create_node($bundle, $title = '', $context = NULL) {
global $user;
$values = array(
'type' => $bundle,
'uid' => $user->uid,
'status' => 1,
'comment' => 0,
'promote' => 0,
);
$entity = entity_create('node', $values);
$wrapper = entity_metadata_wrapper('node', $entity);
$wrapper->title = $title;
$space_id = oa_core_get_space_context();
$section_id = oa_core_get_section_context();
if (isset($context)) {
// copy space and section fields from context node
$context_wrapper = entity_metadata_wrapper('node', $context);
if (isset($context_wrapper->{OA_SPACE_FIELD})) {
$space_id = $context_wrapper->{OA_SPACE_FIELD}
->value();
if (is_array($space_id)) {
// if multi-value space field, just use first space for message
$space_id = array_shift($space_id);
}
}
if (isset($context_wrapper->{OA_SECTION_FIELD})) {
$section_id = $context_wrapper->{OA_SECTION_FIELD}
->value();
}
}
if (isset($wrapper->{OA_SPACE_FIELD})) {
$wrapper->{OA_SPACE_FIELD} = $space_id;
}
if (isset($wrapper->{OA_SECTION_FIELD})) {
$wrapper->{OA_SECTION_FIELD} = $section_id;
}
return $wrapper;
}