save_draft.module in Save Draft 6.2
Same filename and directory in other branches
Main file for the Save Draft module, which adds a 'Save as Draft' button to content types.
File
save_draft.moduleView source
<?php
/**
* @file
* Main file for the Save Draft module, which adds a 'Save as Draft' button to content types.
*/
/**
* Implements hook_form_alter().
*/
function save_draft_form_alter(&$form, &$form_state, $form_id) {
$form_id = substr($form_id, -9);
if ($form_id == 'node_form') {
if (isset($form['nid']['#value'])) {
$form['buttons']['draft'] = array(
'#type' => 'submit',
'#class' => 'form-submit',
'#value' => t('Save as unpublish'),
'#weight' => '9',
'#submit' => array(
'save_draft_submit',
),
);
$form['buttons']['submit']['#value'] = t('Save Changes');
$form['buttons']['submit']['#submit'] = array(
'publish_submit',
);
}
else {
$form['buttons']['draft'] = array(
'#type' => 'submit',
'#class' => 'form-submit',
'#value' => t('Save as Draft'),
'#weight' => '9',
'#submit' => array(
'save_draft_submit',
),
);
$form['buttons']['submit']['#value'] = t('Publish');
$form['buttons']['submit']['#submit'] = array(
'publish_submit',
);
}
}
}
/**
* Handles save draft form submission
*/
function save_draft_submit($form, &$form_state) {
$form_state['values']['status'] = 0;
node_form_submit($form, $form_state);
}
/**
* Handles publish form submission
*/
function publish_submit($form, &$form_state) {
$form_state['values']['status'] = 1;
node_form_submit($form, $form_state);
}
Functions
Name | Description |
---|---|
publish_submit | Handles publish form submission |
save_draft_form_alter | Implements hook_form_alter(). |
save_draft_submit | Handles save draft form submission |