--- saveguard.module.old 2011-03-09 11:44:00.000000000 +0100 +++ saveguard.module 2011-03-09 11:44:16.000000000 +0100 @@ -41,22 +41,58 @@ /** - * Implementation of hook_form_alter(). - * Just add javascript to all forms. - * - * @param $form_id - * name of the form being acted on - * @param $form - * array with form structure - */ +* Implementation of hook_form_alter(). +* Just addd javascript to selected forms. +* +* @param $form_id +* name of the form being acted on +* @param $form +* array with form structure +*/ function saveguard_form_alter(&$form, $form_state, $form_id) { - drupal_add_js(drupal_get_path('module', 'saveguard') .'/saveguard.js'); - static $done; - if (!$done) { - $settings['saveguard'] = array( - 'msg' => variable_get('saveguard_message', NULL), - ); - drupal_add_js($settings, 'setting'); - $done = TRUE; + + if ($form_id == 'node_type_form') { + $options = array(0 => t('Disabled'), 1 => t('Enabled')); + $form['save_guard'] = array( + '#type' => 'fieldset', + '#title' => t('Safe Guard'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#access' => user_access('administer safeguard'), + ); + + $form['save_guard']['save_guard_expose'] = array( + '#type' => 'radios', + '#title' => t('Enable Save Guard for this form'), + '#default_value' => variable_get('save_guard_expose_' . $form['#node_type']->type, 0), + '#description' => t('Enable/Disable SaveGuard for this form.'), + '#options' => $options, + '#weight' => -1, + ); + + } + elseif (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id && is_save_guard_form($form['#node'])) { + drupal_add_js(drupal_get_path('module', 'saveguard') .'/saveguard.js'); + static $done; + if (!$done) { + $settings['saveguard'] = array( + 'msg' => variable_get('saveguard_message', NULL), + ); + drupal_add_js($settings, 'setting'); + $done = TRUE; + } + + } +} + +/** +* Determine if a given node is a SaveGuard Form. +* @param $type +* The node object or the node's type +*/ +function is_save_guard_form($type) { + if (is_object($type)) { + $type = $type->type; } + return variable_get('save_guard_expose_'. $type, 0); }