Posted by El Bandito on January 8, 2013 at 8:17am
Hi
I'd like to add a second submit button the my node form that overrides the content type setting 'Create new revision' which is enabled and submits WITHOUT creating a new revision. In this way my users will be able to save the form frequently without being overwhelmed by revisions if they need to revert.
Problem is I am not sure where to start. Any suggestions or pointers appreciated.
Comments
I can see in the code for
I can see in the code for node_save that it checks whether $node->revision is emty to decide whether a revision is created, but I don't know how this interfaces or otherwise with the node_form submission process ?
I'm still trying. My best,
I'm still trying. My best, but failed attempt, is adding second submit button which runs my custom submit handler prior to the default 'node_form_submit' handler thus :
function ccms_form_form_test_node_form_alter(&$form, &$form_state, $form_id) {
$form['secondsubmit'] = array(
'#type' => 'submit',
'#value' => t('Save ( overwrite )'),
'#weight' => 10,
'#validate' => array('node_form_validate'),
// Use default and an additional submit handler.
'#submit' => array('no_revision_node_form_submit', 'node_form_submit'),
);
}
/**
* Implementation of additional form submit
*/
function no_revision_node_form_submit($form, &$form_state) {
$form_state['values']['revision'] = 0;
}
I was hoping that changing $form_state['values']['revision'] from 1 to 0 would have the required effect but sadly not.
Any guidance would be much appreciated.
I eventually found that I
I eventually found that I have to set $form_state['rebuild'] to TRUE like :
/**
* Implementation of additional form submit
*/
function no_revision_node_form_submit($form, &$form_state) {
$form_state['values']['revision'] = 0;
$form_state['rebuild'] = TRUE;
}
but I don't really understand why. The Form API is mighty confusing.
Any guidance appreciated.
Ignore my nonsense about
Ignore my nonsense about $form_state['rebuild'].