function redirect_save_edit_submit in Save & Edit 7
Same name and namespace in other branches
- 6 save_edit.module \redirect_save_edit_submit()
Custom Submit Handler for Redirecting Save & Edit's to the node form after saving
_state
Parameters
$form:
1 string reference to 'redirect_save_edit_submit'
- save_edit_form_alter in ./
save_edit.module - Implements hook_form_alter().
File
- ./
save_edit.module, line 126 - Save & Edit (http://drupal.org/project/save_edit) Provides a button that gives users the option to Save a form they are working on, AND return to the editing form in one step.
Code
function redirect_save_edit_submit($form, &$form_state) {
// we will first check to see if they want to auto-unpublish, and make modifications if so
// before submitting the node
// ONLY do something on new nodes
if (variable_get('save_edit_unpublish_new_only', 0) && !$form_state['values']['nid']) {
$form_state['values']['status'] = 0;
}
elseif (variable_get('save_edit_unpublish', 0) && !variable_get('save_edit_unpublish_new_only', 0)) {
$form_state['values']['status'] = 0;
}
// WAIT... if someone clicked the Publish button, maybe we should retick that option now
if ($form_state['clicked_button']['#id'] == 'edit-save-edit-publish') {
$form_state['values']['status'] = 1;
}
// call default node save/submit function
node_form_submit($form, $form_state);
// only redirect if using the Save & Edit button
if ($form_state['clicked_button']['#id'] == 'edit-save-edit' || $form_state['clicked_button']['#id'] == 'edit-actions-save-edit') {
// change redirect location
if (isset($_REQUEST['destination'])) {
$form_state['redirect'] = url('node/' . $form_state['nid'] . '/edit', array(
'query' => array(
'destination' => $_REQUEST['destination'],
),
'absolute' => TRUE,
));
$_GET['destination'] = $form_state['redirect'];
unset($_REQUEST['destination']);
}
else {
// just go back to the form edit page, and dont worry about the redirect
$form_state['redirect'] = 'node/' . $form_state['nid'] . '/edit';
}
}
}