function node_node_import_global in Node import 5
Implementation of hook_node_import_global().
File
- supported/
node.inc, line 204
Code
function node_node_import_global($type, $global_values) {
global $user;
$globals = $global_values['node_import_node'];
if (isset($globals['options'])) {
$options = array();
foreach ($globals['options'] as $option => $value) {
if ($value) {
$options[] = $option;
}
}
$globals['options'] = $options;
}
else {
$defaults = array(
'status',
'promote',
);
$globals['options'] = variable_get('node_options_' . $type, $defaults);
}
if (!isset($globals['author'])) {
$globals['author'] = array(
'name' => $user->name,
'date' => '',
);
}
if (!isset($globals['unique_title'])) {
$globals['unique_title'] = 0;
}
// Create a dummy node and get the node form.
$node = array(
'type' => $type,
'date' => date('r'),
'name' => $user->name,
'uid' => $user->uid,
);
$node = array_merge($node, $globals['author']);
foreach ((array) $globals['options'] as $option) {
$node[$option] = 1;
}
$node = (object) $node;
$node_form = node_form($node);
// We only care about a part of this node_form.
$form = array();
$form['node_import_node'] = array(
'#type' => 'fieldset',
'#title' => t('Node options'),
'#description' => t('Select the options you want to assign to all imported nodes unless specifically set otherwise in the CSV file'),
'#tree' => TRUE,
);
foreach (array(
'author',
'options',
) as $fieldset) {
if (isset($node_form[$fieldset])) {
$form['node_import_node'][$fieldset] = $node_form[$fieldset];
if ($fieldset == 'options') {
// The workflow options are overwritten in node_form_array()
// because $node->nid is not set.
foreach (element_children($form['node_import_node']['options']) as $key) {
$form['node_import_node']['options'][$key]['#default_value'] = $node->{$key};
}
}
}
}
// Unique titles?
$form['node_import_node']['unique_title'] = array(
'#type' => 'checkbox',
'#title' => t('Titles must be unique for this node type.'),
'#description' => t('Check this box if you do not want to import nodes if there is already a node with the same title.'),
'#default_value' => $globals['unique_title'],
);
return $form;
}