View source
<?php
function save_edit_help($path, $arg) {
switch ($path) {
case 'admin/settings/save-edit':
return '<p>' . t('Save & Edit adds a "Save and edit" button to the node add and node configure forms. The module also provides options to modify the way the "Publish" feature works when using Save & Edit. If the modifications are enabled to the Publish feature, when a node is unpublished, it will also create a "Publish" button that will obviously Save & Publish a node that was previously marked as Unpublished.') . '</p>';
case 'admin/help#save_edit':
return '<p>' . t('Save & Edit adds a "Save and edit" button to the node add and node configure forms. The module also provides options to modify the way the "Publish" feature works when using Save & Edit. If the modifications are enabled to the Publish feature, when a node is unpublished, it will also create a "Publish" button that will obviously Save & Publish a node that was previously marked as Unpublished.') . '</p>';
default:
return '';
}
}
function save_edit_perm() {
return array(
'use save and edit',
'administer save and edit',
);
}
function save_edit_menu() {
$items = array();
$items['admin/settings/save-edit'] = array(
'title' => t('Save & Edit Settings'),
'description' => t('Administer settings related to the Save & Edit module.'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'save_edit_admin_settings',
),
'access arguments' => array(
'administer save and edit',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function save_edit_admin_settings() {
$form['save_edit_this_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Save & Edit General Features'),
'#description' => t('General settings that will change the usage and/or appearance of the <a href="http://drupal.org/project/save_edit">Save & Edit</a> module.'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['save_edit_this_settings']['save_edit_button_value'] = array(
'#type' => 'textfield',
'#title' => t('Text to use for Save & Edit button'),
'#description' => t('This is the default text that will be used for the button at the bottom of the node form.<br />It would be best to use familiar terms like "<strong>Save & Edit</strong>" or "<strong>Apply</strong>" so that users can easily understand the feature/function related to this option.'),
'#default_value' => variable_get('save_edit_button_value', 'Save & Edit'),
'#required' => TRUE,
);
$form['save_edit_this_settings']['save_edit_button_weight'] = array(
'#type' => 'weight',
'#delta' => 10,
'#description' => t('You may adjust the positioning left to right on the button sections using the weight fields for each button type.'),
'#title' => t('Save & Edit Button Weight'),
'#default_value' => variable_get('save_edit_button_weight', 4),
);
$form['save_edit_this_settings']['save_edit_default_save_button_value'] = array(
'#type' => 'textfield',
'#title' => t('Text to use for default Save button'),
'#description' => t('This will override the default "Save" button text to something more in line with adding the "Save & Edit" and "Save & Publish" options.'),
'#default_value' => variable_get('save_edit_default_save_button_value', 'Save'),
'#required' => TRUE,
);
$form['save_edit_this_settings']['save_edit_default_save_button_weight'] = array(
'#type' => 'weight',
'#delta' => 10,
'#description' => t('You may adjust the positioning left to right on the button sections using the weight fields for each button type.'),
'#title' => t('Default Save Button Weight'),
'#default_value' => variable_get('save_edit_default_save_button_weight', 5),
);
$form['save_edit_this_settings']['save_edit_unpublish'] = array(
'#type' => 'checkbox',
'#title' => t('Auto Unpublish All Nodes'),
'#default_value' => variable_get('save_edit_unpublish', 0),
'#description' => t('This setting will automatically uncheck the "Published" status when using <strong>Save & Edit</strong> button to save nodes.'),
);
$form['save_edit_this_settings']['save_edit_unpublish_new_only'] = array(
'#type' => 'checkbox',
'#title' => t('Auto Unpublish on New Nodes Only'),
'#default_value' => variable_get('save_edit_unpublish_new_only', 0),
'#description' => t('This will only mark the node as unpublished upon creating a new node. Assuming this is used, on subsequent uses of <strong>Save & Edit</strong> the node will be unpublished already, and NOT affected. You will be required at some point to manually publish the node using the optional <strong>Publish</strong> button, or manually ticking the appropriate checkbox when hitting the default Save button.'),
);
$form['save_edit_this_settings']['save_edit_publish_button_value'] = array(
'#type' => 'textfield',
'#title' => t('Text to use for Publish button'),
'#description' => t('This is the default text that will be used for the Publish button. <em>Note: This button will ONLY appear if you have checked either of the above options that manipulate the default publishing actions provided by Drupal.</em>'),
'#default_value' => variable_get('save_edit_publish_button_value', 'Publish'),
'#required' => TRUE,
);
$form['save_edit_this_settings']['save_edit_publish_button_weight'] = array(
'#type' => 'weight',
'#delta' => 10,
'#description' => t('You may adjust the positioning left to right on the button sections using the weight fields for each button type.'),
'#title' => t('Publish Button Weight'),
'#default_value' => variable_get('save_edit_publish_button_weight', 7),
);
$form['where_to_save_edit'] = array(
'#type' => 'fieldset',
'#title' => t('Node Types'),
'#description' => t('Set the node types you want to display links for.'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['where_to_save_edit']['save_edit_node_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Node types'),
'#default_value' => variable_get('save_edit_node_types', array()),
'#options' => node_get_types('names'),
);
return system_settings_form($form);
}
function save_edit_form_alter(&$form, $form_state, $form_id) {
$node_types = variable_get('save_edit_node_types', array());
$form_type = $form['type']['#value'];
if ($form['#id'] == 'node-form' && $node_types[$form_type] && user_access('use save and edit')) {
$form['buttons']['save_edit'] = array(
'#type' => 'submit',
'#access' => user_access('use save and edit'),
'#value' => t(check_plain(variable_get('save_edit_button_value', 'Save and Edit'))),
'#weight' => variable_get('save_edit_button_weight', 4),
'#submit' => array(
'redirect_save_edit_submit',
),
);
if ((variable_get('save_edit_unpublish', 0) || variable_get('save_edit_unpublish_new_only', 0)) && !$form['#node']->status) {
$form['buttons']['save_edit_publish'] = array(
'#type' => 'submit',
'#access' => user_access('use save and edit'),
'#value' => t(check_plain(variable_get('save_edit_publish_button_value', 'Save and Publish'))),
'#weight' => variable_get('save_edit_publish_button_weight', 7),
'#submit' => array(
'redirect_save_edit_submit',
),
);
}
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#access' => !variable_get('node_preview', 0) || !form_get_errors() && isset($form_state['node_preview']),
'#value' => t(check_plain(variable_get('save_edit_default_save_button_value', 'Save'))),
'#weight' => variable_get('save_edit_default_save_button_weight', 5),
'#submit' => array(
'node_form_submit',
),
);
$form['buttons']['save_edit']['#submit'] = array(
'redirect_save_edit_submit',
);
}
}
function redirect_save_edit_submit($form, &$form_state) {
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;
}
if ($form_state['clicked_button']['#id'] == 'edit-save-edit-publish') {
$form_state['values']['status'] = 1;
}
node_form_submit($form, $form_state);
if ($form_state['clicked_button']['#id'] == 'edit-save-edit') {
if ($_REQUEST['destination']) {
$form_state['redirect'] = url('node/' . $form_state['nid'] . '/edit', array(
'query' => array(
'destination' => $_REQUEST['destination'],
),
'absolute' => TRUE,
));
unset($_REQUEST['destination']);
}
else {
$form_state['redirect'] = 'node/' . $form_state['nid'] . '/edit';
}
}
}