Skip to content

Instantly share code, notes, and snippets.

@nucklearproject
Created September 21, 2012 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nucklearproject/3762249 to your computer and use it in GitHub Desktop.
Save nucklearproject/3762249 to your computer and use it in GitHub Desktop.
Save and return to edit new or update node.
<?php
/**
* @file
* Replace the submit button to node creation forms that
* allows the content author to return to edit the node
*/
/**
* Implementation of hook_form_alter().
*/
/**
* Alter content type settings to add "Save node and return to edit" checkbox
*/
function saveandreturn_form_node_type_form_alter(&$form, &$form_state) {
if (isset($form['identity']['type'])) {
$form['submission']['saveandreturn'] = array(
'#type' => 'checkbox',
'#title' => t('Save and Edit'),
'#default_value' => variable_get('saveandreturn_'. $form['#node_type']->type, FALSE),
'#description' => t('Enable this checkbox if you want to provide a "Save node and return to edit"')
);
}
}
function saveandreturn_form_alter(&$form, $form_state, $form_id) {
/* Remove all preview nodes buttom */
if(strpos($form_id, '_node_form')){
unset($form['buttons']['preview']);
}
if(strpos($form_id, '_node_form') && !isset($form['nid']['#value'])) {
if (variable_get('saveandreturn_'. $form['type']['#value'], FALSE)) {
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save and Edit'),
'#weight' => -41,
'#submit' => array('node_form_submit', 'saveandreturn_node_form_submit'),
);
}
}
}
function saveandreturn_node_form_submit($form, &$form_state) {
//$link = l(t('Visit your new post.'), 'node/'. $form_state['nid']);
drupal_set_message('Your post was successfully saved!');
$form_state['redirect'] = NULL;
unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment