multi_node_add.module in Multi Node Add 7
Same filename and directory in other branches
Allows to create multiple nodes using one page, one form submission. Highly depends on Javascript.
File
multi_node_add.moduleView source
<?php
/**
* @file
* Allows to create multiple nodes using one page, one form submission.
* Highly depends on Javascript.
*/
/**
* Implements hook_menu().
*/
function multi_node_add_menu() {
$items = array();
$items['multi_node_add'] = array(
'title' => 'Create multiple nodes',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'multi_node_add_page',
),
'access callback' => '_node_add_access',
'file' => 'multi_node_add.pages.inc',
);
foreach (node_type_get_types() as $type) {
$type_url_str = str_replace('_', '-', $type->type);
$items['multi_node_add/' . $type_url_str] = array(
'title' => drupal_ucfirst($type->name),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'multi_node_add_page',
1,
),
'access callback' => 'node_access',
'access arguments' => array(
'create',
$type->type,
),
'description' => $type->description,
'type' => MENU_LOCAL_TASK,
'file' => 'multi_node_add.pages.inc',
);
$items['multi_node_add/frame/' . $type_url_str] = array(
'type' => MENU_CALLBACK,
'access callback' => 'node_access',
'access arguments' => array(
'create',
$type->type,
),
'page callback' => 'multi_node_add_frame_page',
'page arguments' => array(
$type->type,
),
'file' => 'multi_node_add.pages.inc',
);
$items['multi_node_add/status/' . $type_url_str . '/%node/%'] = array(
'type' => MENU_CALLBACK,
'access callback' => 'node_access',
'access arguments' => array(
'create',
$type->type,
),
'page callback' => 'multi_node_add_frame_status',
'page arguments' => array(
3,
4,
),
'file' => 'multi_node_add.pages.inc',
);
}
return $items;
}
/**
* Implements hook_form_alter().
*
* Modifies the node form according to the multi_node_add_page() form config.
*/
function multi_node_add_form_alter(&$form, &$form_state, $form_id) {
if (arg(0) == 'multi_node_add' && strstr($form_id, '_node_form') !== FALSE || isset($form_state['multi_node_add_fields_show'])) {
$form['#after_build'][] = 'multi_node_add_node_form_after_build';
$form['actions']['submit']['#submit'][] = 'multi_node_add_node_form_submit';
if (!isset($form_state['multi_node_add_fields_show'])) {
$form_state['multi_node_add_fields_show'] = explode(',', arg(3));
}
}
}
/**
* Modifies the node form according to the choices of the user.
*/
function multi_node_add_node_form_after_build($form, &$form_state) {
unset($form['actions']['preview']);
$form['actions']['submit']['#value'] = t('Create');
$fields = field_info_instances('node', $form['#node']->type);
$field_names = array_keys($form);
foreach ($field_names as $field_name) {
if (isset($fields[$field_name]) && !in_array($field_name, $form_state['multi_node_add_fields_show'])) {
$form[$field_name]['#access'] = FALSE;
}
}
return $form;
}
/**
* Redirects the iFrame to the simple result page instead of full node page.
*/
function multi_node_add_node_form_submit($form, &$form_state) {
$form_state['redirect'] = 'multi_node_add/status/' . arg(2) . '/' . $form_state['nid'] . '/' . $_GET['view'];
drupal_get_messages();
}
Functions
Name | Description |
---|---|
multi_node_add_form_alter | Implements hook_form_alter(). |
multi_node_add_menu | Implements hook_menu(). |
multi_node_add_node_form_after_build | Modifies the node form according to the choices of the user. |
multi_node_add_node_form_submit | Redirects the iFrame to the simple result page instead of full node page. |