function multi_node_add_page in Multi Node Add 7
Same name and namespace in other branches
- 6 multi_node_add.module \multi_node_add_page()
Provides a page where the fields to use to create the nodes can be selected.
1 string reference to 'multi_node_add_page'
- multi_node_add_menu in ./
multi_node_add.module - Implements hook_menu().
File
- ./
multi_node_add.pages.inc, line 11 - Contains the logic of the configuration form and the iframe-related codes.
Code
function multi_node_add_page($form, &$form_state, $type = FALSE) {
if ($type == FALSE) {
$all_types = array_keys(node_type_get_types());
$type = end($all_types);
drupal_goto('multi_node_add/' . str_replace('_', '-', $type));
}
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(
'multiNodeAdd' => $settings,
), 'setting');
$prefilled = FALSE;
if (isset($_GET['fields']) && isset($_GET['num'])) {
drupal_add_js(array(
'multiNodeAddPreload' => array(
'fields' => explode(',', $_GET['fields']),
'num' => $_GET['num'],
'view' => !empty($_GET['view']) ? 1 : 0,
),
), 'setting');
$prefilled = TRUE;
}
if (!$prefilled) {
$type = str_replace('-', '_', $type);
$fields = field_info_instances('node', $type);
$extra = field_info_extra_fields('node', $type, 'form');
$req_val = array();
$field_req = array();
$field_names = array();
foreach ($extra as $field_name => $entry) {
$field_req[$field_name] = $entry['label'];
$req_val[$field_name] = $field_name;
}
foreach ($fields as $field_name => $entry) {
if ($entry['required']) {
$field_req[$field_name] = $entry['label'];
$req_val[$field_name] = $field_name;
}
else {
$field_names[$field_name] = $entry['label'];
}
}
$form = array();
$form['hint']['#markup'] = '<noscript><div class="warning messages">' . t('Multi Node Add requires Javascript to provide the needed functionality') . '</div></noscript>';
$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' => array(
'multi-node-add',
),
),
'#disabled' => TRUE,
);
}
if (!empty($field_names)) {
$form['fields_to_utilize'] = array(
'#type' => 'checkboxes',
'#options' => $field_names,
'#title' => t('Fields to manage'),
'#attributes' => array(
'class' => array(
'multi-node-add',
),
),
'#description' => t('Choose those fields that you would like to edit on the new nodes'),
);
$form['check_all'] = array(
'#type' => 'button',
'#value' => t('Check all'),
);
$form['uncheck_all'] = array(
'#type' => 'button',
'#value' => t('Uncheck all'),
);
}
// If there are no available fields, we should not offer a form.
if (empty($field_names) && empty($field_req)) {
drupal_set_message(t('Unable to generate multiple nodes for this content type (failed to detect usable fields).'), 'warning');
return $form;
}
$form['number'] = array(
'#type' => 'textfield',
'#default_value' => 2,
'#size' => 2,
'#required' => TRUE,
'#title' => t('Number of rows'),
);
$form['view'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
'#title' => t('Display node after saving it'),
);
$form['show'] = array(
'#type' => 'button',
'#value' => t('Show'),
);
$form['shortcut'] = array(
'#type' => 'button',
'#value' => t('Get shortcut URL'),
);
}
$common_attr = array(
'#attributes' => array(
'class' => array(
'second-step',
),
),
);
$form['addmore'] = array(
'#type' => 'button',
'#value' => t('Add 2 more nodes'),
) + $common_attr;
$form['create'] = array(
'#type' => 'button',
'#value' => t('Create all nodes'),
) + $common_attr;
$form['prepopulate'] = array(
'#type' => 'button',
'#value' => t('Prepopulate based on first form'),
) + $common_attr;
$form['options']['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset'),
);
$form['placeholder']['#markup'] = '<div id="multi_node_add_frames"></div>';
return $form;
}