function _vsd_if_examples_import_create_node in Views Slideshow: Dynamic Display Block 6.2
Create example node.
Parameters
$node_type: node_type of the node to add
$files: files to add to the node
$slide: Array with slide fields: title, body, slide_text, pager_item_text
Return value
$node object
1 call to _vsd_if_examples_import_create_node()
- vsd_if_examples_install in vsd_if_examples/
vsd_if_examples.install - Implementation of hook_install().
File
- vsd_if_examples/
includes/ vsd_if_examples.nodedata.inc, line 21 - data import for vsd_if_examples module
Code
function _vsd_if_examples_import_create_node($node_type, $files, $slide) {
global $user;
// For node_object_prepare()
module_load_include('inc', 'node', 'node.pages');
$node = new stdClass();
$node->type = $node_type;
$node->name = $user->name;
$node->title = $slide['node_title'];
$node->body = $slide['node_body'];
$node->format = 2;
// full html
// Prepares a node object for editing.
// Fills in a few default values from the content type:
// $node->status (0 - unpublished, 1 - published) from node_type - defaults to 0
// $node->promote (0 - don't promote to frontpage, 1 - promote to frontpage) from node_type - defaults to 0
// $node->sticky (0 - no, 1 - yes) defaults to 0
// $node->uid = $user-uid
// $node->created = time()
// $node->revision = defaults to 0
// and then invokes hook_prepare() on the node type module,
// and hook_node_prepare() on all modules.
node_object_prepare($node);
// override $node->status, set to published
$node->status = 1;
// published
// set slidetext and pager_item_text values
$node->field_ddblock_if_slide_text[0] = array(
'value' => $slide['slide_text'],
);
$node->field_ddblock_if_pager_item_text[0] = array(
'value' => $slide['pager_item_text'],
);
// Get the filefield module to do the saving and marking the record as permanent.
foreach ($files as $field_name => $file) {
if (isset($node->{$field_name})) {
array_push($node->{$field_name}, $file);
}
else {
$node->{$field_name} = array(
0 => $file,
);
}
}
// Prepare node for save and allow modules to make changes
$node = node_submit($node);
// Save node object into the database.
node_save($node);
return $node;
}