Index: journal.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/journal/journal.module,v
retrieving revision 1.1.2.5
diff -u -p -r1.1.2.5 journal.module
--- journal.module	16 Apr 2008 19:19:47 -0000	1.1.2.5
+++ journal.module	16 Apr 2008 20:39:00 -0000
@@ -57,21 +57,30 @@ function journal_menu($may_cache) {
 /**
  * Add Journal fields to all forms.
  * 
- * Any form, except a few pre-defined form_ids, will be extended by a fieldset
- * to enter a journal entry.
+ * Any form, except user-defined form_ids, will be extended by a fieldset
+ * to enter a journal entry.  All journal form ids are stored in one variable
+ * array; having form_ids as keys and a boolean value whether to skip a form id
+ * (0) or force/require a journal entry for it (1).
  *
- * @see journal_skip_form()
+ * @see journal_form_ids_default()
  */
 function journal_form_alter($form_id, &$form) {
   if (!user_access('access journal')) {
     return;
   }
-  // Do not extend this form, if it is in the list of form_ids to skip.
-  if (journal_skip_form($form_id)) {
-    return;
+  // Check whether form has to/must not be extended.
+  $journal_ids = variable_get('journal_form_ids', journal_form_ids_default());
+  if (isset($journal_ids[$form_id])) {
+    if (!$journal_ids[$form_id] && $form['#base'] != 'system_settings_form') {
+      // No journal entry for 'form_id' => 0.
+      return;
+    }
+    else {
+      // Require journal entry for 'form_id' => 1.
+      $entry_required = TRUE;
+    }
   }
-  $entry_required = FALSE;
-  
+
   // Shift system_settings_form buttons.
   if (isset($form['#base']) && $form['#base'] == 'system_settings_form') {
     $weight = $form['buttons']['#weight'];
@@ -122,18 +131,14 @@ function journal_form_submit($form_id, $
  * @todo Introduce a new FAPI attribute #journal = TRUE to require a journal
  *   entry if Journal module is enabled - OR - introduce a new hook_journal?
  */
-function journal_skip_form($form_id) {
-  $skip_ids = array(
-    'devel_switch_user_form',
-    'search_block_form',
-    'search_theme_form',
-    'user_filter_form',
-    'user_login_block',
+function journal_form_ids_default() {
+  return array(
+    'devel_switch_user_form' => 0,
+    'search_block_form' => 0,
+    'search_theme_form' => 0,
+    'user_filter_form' => 0,
+    'user_login_block' => 0,
   );
-  if (in_array($form_id, $skip_ids)) {
-    return TRUE;
-  }
-  return FALSE;
 }
 
 /**
@@ -313,3 +318,48 @@ function journal_add_entry($description)
   db_query("INSERT INTO {journal} (jid, uid, message, location, timestamp) VALUES (%d, %d, '%s', '%s', %d)", $jid, $user->uid, $description, $_GET['q'], time());
 }
 
+/**
+ * Implementation of hook_form_controller().
+ *
+ * @param string $op
+ *   The operation performed.
+ * @param mixed $edit
+ *   For operation
+ *   - 'settings' a form id.
+ *   - 'validate' a form_values array containing only settings of this
+ *     implementation.  Use the module as prefix for form_set_error(), e.g.
+ *     form_set_error('mymodule][mysetting', ...).
+ *   - 'submit' a form_values array containing only settings of this
+ *     implementation.
+ */
+function journal_form_controller($op, $edit = array()) {
+  switch ($op) {
+    case 'settings':
+      $journal_ids = variable_get('journal_form_ids', array());
+      $form = array();
+      $form['journal'] = array(
+        '#type' => 'radios',
+        '#title' => t('Journal entry'),
+        '#options' => array(
+          0 => t('Disable'),
+          -1 => t('Allow'),
+          1 => t('Required'),
+        ),
+        '#default_value' => isset($journal_ids[$edit]) ? $journal_ids[$edit] : -1,
+        '#description' => t('Whether journal entries for this form should be allowed, required, or completely disabled.'),
+      );
+      return $form;
+
+    case 'submit':
+      $journal_ids = variable_get('journal_form_ids', array());
+      if ($edit['journal'] != -1) {
+        $journal_ids = array_merge($journal_ids, array($edit['#form_id'] => (int)$edit['journal']));
+      }
+      else {
+        unset($journal_ids[$edit['#form_id']]);
+      }
+      variable_set('journal_form_ids', $journal_ids);
+      break;
+  }
+}
+
