summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkonradryw2012-12-28 02:32:43 (GMT)
committer konradryw2012-12-28 02:32:43 (GMT)
commit548168646aee6b0a46d575e24e3d04eb2fb18c63 (patch)
tree2ca5b27c3e9a76e739089e4dc7271823e34f9c84
parent3ad0ad4b2e06ab43c63ada1ae5b22d1bacdbbf6d (diff)
node save state enable checkboxHEADmaster
-rw-r--r--node_save_state/node_save_state.module67
1 files changed, 59 insertions, 8 deletions
diff --git a/node_save_state/node_save_state.module b/node_save_state/node_save_state.module
index a380b6f..020efca 100644
--- a/node_save_state/node_save_state.module
+++ b/node_save_state/node_save_state.module
@@ -19,7 +19,40 @@ function node_save_state_form_alter(&$form, &$form_state, $form_id) {
$reset = variable_get('node_save_state_reset', FALSE);
+ //add checkbox that enables 'save node state' for a given content type
+ if ($form['#form_id'] == 'node_type_form') {
+ $form['#submit'][] = 'node_save_state_content_type_submit';
+ $type = $form['type']['#default_value'];
+ $form_state['values']['type'] = $type;
+ $node_save_state_enable = variable_get('node_save_state_enable', array());
+
+ $existing = ($node_save_state_enable[$type]['existing'] == 1) ? 1 : 0;
+ $new = ($node_save_state_enable[$type]['new'] == 1) ? 1 : 0;
+
+ $form['node_save_state_settings'] = array(
+ '#type' => 'fieldset',
+ '#title' => 'Node Save State settings',
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ '#group' => 'additional_settings',
+ );
+
+ $form['node_save_state_settings']['new_node'] = array(
+ '#type' => 'checkbox',
+ '#title' => 'New node',
+ '#default_value' => $new,
+ '#description' => 'Enable node save state option for creating a new node',
+ );
+
+ $form['node_save_state_settings']['existing_node'] = array(
+ '#type' => 'checkbox',
+ '#title' => 'Existing nodes',
+ '#default_value' => $existing,
+ '#description' => 'Enable node save state option for existing nodes',
+ );
+
+ }
if (isset($form['nid'])) {
global $user;
@@ -33,7 +66,11 @@ function node_save_state_form_alter(&$form, &$form_state, $form_id) {
$form_state['values']['type'] = $type;
$form_state['values']['nid'] = $nid;
- if (!$reset) {
+ $node_save_state_enable = variable_get('node_save_state_enable', array());
+ $enable = ($nid == 0) ? $node_save_state_enable[$type]['new'] : $node_save_state_enable[$type]['existing'];
+krumo($node_save_state_enable);
+krumo($enable);
+ if (!$reset && $enable) {
$result = db_select('node_save_state', 'n')
->fields('n')
@@ -137,13 +174,16 @@ function node_save_state_form_alter(&$form, &$form_state, $form_id) {
}
}
- $form['save_state'] = array(
- '#access' => user_access('node save state'),
- '#type' => 'submit',
- '#value' => t('Save Node State'),
- '#weight' => 100,
- '#submit' => array('node_save_state_form_submit'),
- );
+ if ($enable) {
+
+ $form['save_state'] = array(
+ '#access' => user_access('node save state'),
+ '#type' => 'submit',
+ '#value' => t('Save Node State'),
+ '#weight' => 100,
+ '#submit' => array('node_save_state_form_submit'),
+ );
+ }
}
@@ -271,4 +311,15 @@ function node_reset_state_form_submit($form, &$form_state) {
drupal_get_messages('status', TRUE);
//drupal_set_message('Test reset');
+}
+
+function node_save_state_content_type_submit($form, &$form_state) {
+
+ $type = $form_state['values']['type'];
+ $new = $form_state['values']['new_node'];
+ $exisiting = $form_state['values']['existing_node'];
+ $node_save_state_enable = variable_get('node_save_state_enable', array());
+ $node_save_state_enable[$type]['new'] = $new;
+ $node_save_state_enable[$type]['existing'] = $exisiting;
+ $node_save_state_enable = variable_set('node_save_state_enable', $node_save_state_enable);
} \ No newline at end of file