function oa_wizard_modal_callback in Open Atrium Wizard 7.2
Node add modal callback.
1 string reference to 'oa_wizard_modal_callback'
- oa_wizard_menu in ./
oa_wizard.module - Implements hook_menu().
File
- ./
oa_wizard.module, line 102 - Code for the OpenAtrium Wizard.
Code
function oa_wizard_modal_callback($wizard_name) {
global $user;
// Include your ctools stuff here
ctools_include('node.pages', 'node', '');
ctools_include('modal');
ctools_include('ajax');
$wizard_name = str_replace('-', '_', $wizard_name);
$wizard = oa_wizard_machine_name_load($wizard_name);
if (!$wizard || empty($wizard->field_wizard_type[LANGUAGE_NONE][0]['value']) || !node_access('create', $wizard->field_wizard_type[LANGUAGE_NONE][0]['value'])) {
drupal_set_message(t('Unable to load wizard'), 'error');
return drupal_access_denied();
}
$node_type = $wizard->field_wizard_type[LANGUAGE_NONE][0]['value'];
$steps = oa_wizard_get_steps($wizard_name);
// include the js and css for the wizards
$base = drupal_get_path('module', 'oa_wizard');
drupal_add_js($base . '/js/oa_wizard.js');
drupal_add_js(array(
'oa_wizard' => array(
'steps' => $steps,
),
), 'setting');
drupal_add_css($base . '/css/oa_wizard.css');
// Create a blank node object here. You can also set values for your custom fields here as well.
$node = (object) array(
'uid' => $user->uid,
'name' => isset($user->name) ? $user->name : '',
'type' => $node_type,
'language' => LANGUAGE_NONE,
'is_new' => TRUE,
);
$form_state = array(
'title' => t('Add New @name', array(
'@name' => node_type_get_name($node_type),
)),
'ajax' => TRUE,
'no_redirect' => TRUE,
);
$form_state['build_info']['args'] = array(
$node,
);
$form_state['build_info']['oa_wizard'] = $wizard_name;
// change this to your type node form
$output = ctools_modal_form_wrapper($node_type . '_node_form', $form_state);
// This means the form has been exectued
if (!empty($form_state['executed'])) {
$output = array();
// Close the modal
$output[] = ctools_modal_command_dismiss();
if ($url =& drupal_static('oa_wizard_redirect')) {
$output[] = array(
// The command will be used in our JavaScript file (see next section)
'command' => 'oaWizardRedirect',
'url' => $url,
);
}
else {
$form_state['node']->node_token = drupal_get_token('sitemap-node-' . $form_state['node']->nid);
$output[] = array(
// The command will be used in our JavaScript file (see next section)
'command' => 'oaWizardNew',
// We pass the value that the user selected in the select element to our
// JavaScript function:
'node' => $form_state['node'],
);
}
}
print ajax_render($output);
exit;
}