function multi_node_add_page in Multi Node Add 6
Same name and namespace in other branches
- 7 multi_node_add.pages.inc \multi_node_add_page()
Provides a page where the user can select between the fields to use to create the nodes.
1 string reference to 'multi_node_add_page'
- multi_node_add_menu in ./
multi_node_add.module - Implementation of hook_menu().
File
- ./
multi_node_add.module, line 69 - This module allows to create multiple nodes using one page, one form submission. Uses AJAX.
Code
function multi_node_add_page($form_state = array(), $type = FALSE) {
if ($type == FALSE) {
$type = array_shift(array_keys(node_get_types('names')));
}
drupal_add_js(drupal_get_path('module', 'multi_node_add') . '/multi_node_add.js');
$settings = array(
'callback' => url('multi_node_add/frame/' . $type, array(
'absolute' => TRUE,
)),
);
drupal_add_js(array(
'multi_node_add' => $settings,
), 'setting');
$prefilled = FALSE;
if (isset($_GET['fields']) && isset($_GET['num'])) {
drupal_add_js(array(
'multi_node_add_preload' => array(
'fields' => explode(',', $_GET['fields']),
'num' => $_GET['num'],
),
), 'setting');
$prefilled = TRUE;
}
if (!$prefilled) {
$type = str_replace('-', '_', $type);
$fields = array();
// CCK fields
module_load_include('inc', 'content', 'includes/content.crud');
if (function_exists('content_field_instance_read')) {
$fields += content_field_instance_read(array(
'type_name' => $type,
));
}
$fields += _multi_node_add_non_cck_fields($type);
$field_names = array();
$field_req = array();
$req_val = array();
foreach ($fields as $field) {
if ($field['field_def'][$field['field_name']]['#required'] == TRUE || $field['required'] == TRUE) {
if ($field['field_def'][$field['field_name']]['#required'] == TRUE) {
$field_req[$field['field_name']] = $field['field_def'][$field['field_name']]['#title'];
}
else {
if ($field['active']) {
$field_req[$field['field_name']] = $field['widget']['label'];
}
}
$req_val[$field['field_name']] = $field['field_name'];
}
else {
if (!empty($field['field_def'][$field['field_name']]['#title'])) {
$field_names[$field['field_name']] = $field['field_def'][$field['field_name']]['#title'];
}
if (!empty($field['widget']['label'])) {
if ($field['widget_active']) {
$field_names[$field['field_name']] = $field['widget']['label'];
}
}
}
}
// Taxonomy support, are there any vocabs?
$vocabs = taxonomy_get_vocabularies($type);
if (!empty($vocabs)) {
$field_names['taxonomy'] = t('Taxonomy, %vocabs vocabularies', array(
'%vocabs' => count($vocabs),
));
}
$form = array();
$form['info']['#value'] = t('Current content-type: %type', array(
'%type' => $type,
));
if (!empty($field_req)) {
$form['fields_req'] = array(
'#type' => 'checkboxes',
'#options' => $field_req,
'#default_value' => $req_val,
'#title' => t('Mandatory fields'),
'#attributes' => array(
'class' => 'multi-node-add',
),
'#disabled' => TRUE,
);
}
$form['fields_to_utilize'] = array(
'#type' => 'checkboxes',
'#options' => $field_names,
'#title' => t('Fields to manage'),
'#attributes' => array(
'class' => 'multi-node-add',
),
'#description' => t('Choose those fields that you would like to edit on the new nodes'),
);
$form['number'] = array(
'#type' => 'textfield',
'#default_value' => 2,
'#size' => 2,
'#required' => TRUE,
'#title' => t('Number of rows'),
);
$form['show'] = array(
'#type' => 'button',
'#value' => t('Show'),
);
$form['shortcut'] = array(
'#type' => 'button',
'#value' => t('Get shortcut URL'),
);
}
$form['addmore'] = array(
'#type' => 'button',
'#value' => t('Add 2 more nodes'),
);
$form['create'] = array(
'#type' => 'button',
'#value' => t('Create all nodes'),
);
$form['placeholder']['#value'] = '<div id="multi_node_add_frames"></div>';
return $form;
}