Index: journal.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/journal/journal.module,v retrieving revision 1.1.2.4 diff -u -p -r1.1.2.4 journal.module --- journal.module 24 Feb 2008 04:58:25 -0000 1.1.2.4 +++ journal.module 29 Feb 2008 03:27:28 -0000 @@ -57,8 +57,16 @@ 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). Typical examples: + * @code + * array( + * 'search_block_form' => 0, + * 'user_access_form' => 1, + * ) + * @endcode * * @see journal_skip_form() */ @@ -66,12 +74,19 @@ function journal_form_alter($form_id, &$ 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', array()); + 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']; @@ -109,34 +124,6 @@ function journal_form_submit($form_id, $ } /** - * Indicate if a form must not extended. - * - * @param string $form_id - * A form_id to check against. - * - * @return bool - * True if form should be skipped, false if form can be extended. - * - * @todo Fetch custom form_ids from a variable. - * @todo Allow to define custom form_ids in a settings page? - * @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', - ); - if (in_array($form_id, $skip_ids)) { - return TRUE; - } - return FALSE; -} - -/** * Implementation of hook_user(). */ function journal_user($op, &$edit, &$user) { @@ -269,3 +256,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; + } +} +