Index: modules/filter/filter.module =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v retrieving revision 1.284 diff -u -r1.284 filter.module --- modules/filter/filter.module 27 Aug 2009 21:18:19 -0000 1.284 +++ modules/filter/filter.module 28 Aug 2009 16:10:54 -0000 @@ -53,6 +53,10 @@ 'arguments' => array('form' => NULL), 'file' => 'filter.admin.inc', ), + 'filter_admin_format_form' => array( + 'arguments' => array('form' => NULL), + 'file' => 'filter.admin.inc', + ), 'filter_tips' => array( 'arguments' => array('tips' => NULL, 'long' => FALSE), 'file' => 'filter.pages.inc', @@ -70,6 +74,13 @@ * Implement hook_menu(). */ function filter_menu() { + $items['filter/tips'] = array( + 'title' => 'Compose tips', + 'page callback' => 'filter_tips_long', + 'access callback' => TRUE, + 'type' => MENU_SUGGESTED_ITEM, + 'file' => 'filter.pages.inc', + ); $items['admin/settings/formats'] = array( 'title' => 'Text formats', 'description' => 'Configure how content input by users is filtered, including allowed HTML tags. Also allows enabling of module-provided filters.', @@ -90,13 +101,6 @@ 'weight' => 1, 'file' => 'filter.admin.inc', ); - $items['filter/tips'] = array( - 'title' => 'Compose tips', - 'page callback' => 'filter_tips_long', - 'access callback' => TRUE, - 'type' => MENU_SUGGESTED_ITEM, - 'file' => 'filter.pages.inc', - ); $items['admin/settings/formats/%filter_format'] = array( 'type' => MENU_CALLBACK, 'title callback' => 'filter_admin_format_title', @@ -106,29 +110,6 @@ 'access arguments' => array('administer filters'), 'file' => 'filter.admin.inc', ); - $items['admin/settings/formats/%filter_format/edit'] = array( - 'title' => 'Edit', - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => 0, - ); - $items['admin/settings/formats/%filter_format/configure'] = array( - 'title' => 'Configure', - 'page callback' => 'filter_admin_configure_page', - 'page arguments' => array(3), - 'access arguments' => array('administer filters'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 1, - 'file' => 'filter.admin.inc', - ); - $items['admin/settings/formats/%filter_format/order'] = array( - 'title' => 'Rearrange', - 'page callback' => 'filter_admin_order_page', - 'page arguments' => array(3), - 'access arguments' => array('administer filters'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'filter.admin.inc', - ); $items['admin/settings/formats/%filter_format/delete'] = array( 'title' => 'Delete text format', 'page callback' => 'drupal_get_form', @@ -185,15 +166,14 @@ // to the bottom. $current = filter_list_format($format->format); $filters = $format->filters; - - foreach ($filters as $name => $status) { + foreach ($filters as $name => $filter) { $fields = array(); // Add new filters to the bottom. $fields['weight'] = isset($current[$name]->weight) ? $current[$name]->weight : 10; - $fields['status'] = $status; + $fields['status'] = $filter['status']; // Only update settings if there are any. - if (!empty($format->settings[$name])) { - $fields['settings'] = serialize($format->settings[$name]); + if (!empty($filter->settings)) { + $fields['settings'] = serialize($filter['settings']); } db_merge('filter') ->key(array( @@ -211,6 +191,7 @@ module_invoke_all('filter_format_update', $format); } + // Clear the filter cache whenever a text format is saved. cache_clear_all($format->format . ':', 'cache_filter', TRUE); return $return; @@ -472,27 +453,32 @@ } /** - * Retrieve a list of filters for a certain format. + * Retrieve the filters configuration of a given text format. * * @param $format * The format ID. + * @param $all + * Whether to retrieve the configuration for all filters or only the enabled + * filters. TRUE retrieve all the filters, FALSE (default) only the enabled. * @return * An array of filter objects assosiated to the given format. */ -function filter_list_format($format) { +function filter_list_format($format, $all = FALSE) { static $filters = array(); $filter_info = filter_get_filters(); - if (!isset($filters[$format])) { + if (!isset($filters[$format]) || $all) { $filters[$format] = array(); - $result = db_select('filter', 'filter') + $query = db_select('filter', 'filter') ->fields('filter') ->condition('format', $format) - ->condition('status', 1) ->orderBy('weight') ->orderBy('module') - ->orderBy('name') - ->execute(); + ->orderBy('name'); + if (!$all) { + $query->condition('status', 1); + } + $result = $query->execute(); foreach ($result as $filter) { if (isset($filter_info[$filter->name])) { $filter->title = $filter_info[$filter->name]['title']; Index: modules/filter/filter.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.admin.inc,v retrieving revision 1.41 diff -u -r1.41 filter.admin.inc --- modules/filter/filter.admin.inc 27 Aug 2009 21:18:19 -0000 1.41 +++ modules/filter/filter.admin.inc 28 Aug 2009 16:10:49 -0000 @@ -14,10 +14,8 @@ * @see filter_admin_overview_submit() */ function filter_admin_overview() { - // Overview of all formats. $formats = filter_formats(); - $error = FALSE; $form = array('#tree' => TRUE); foreach ($formats as $id => $format) { @@ -32,7 +30,7 @@ $options[$id] = ''; $form[$id]['name'] = array('#markup' => $format->name); $form[$id]['roles'] = array('#markup' => $default ? t('All roles may use the default format') : ($roles ? implode(', ', $roles) : t('No roles may use this format'))); - $form[$id]['configure'] = array('#markup' => l(t('configure'), 'admin/settings/formats/' . $id)); + $form[$id]['edit'] = array('#markup' => l(t('edit'), 'admin/settings/formats/' . $id)); $form[$id]['delete'] = array('#markup' => $default ? '' : l(t('delete'), 'admin/settings/formats/delete/' . $id)); $form[$id]['weight'] = array('#type' => 'weight', '#default_value' => $format->weight); } @@ -76,7 +74,7 @@ drupal_render($element['roles']), drupal_render($form['default'][$id]), drupal_render($element['weight']), - drupal_render($element['configure']), + drupal_render($element['edit']), drupal_render($element['delete']), ), 'class' => array('draggable'), @@ -118,49 +116,69 @@ $form['default_format'] = array('#type' => 'hidden', '#value' => 1); } - $form['name'] = array('#type' => 'textfield', + $form = array( + '#tree' => TRUE, + '#attached_js' => array( + drupal_get_path('module', 'filter') . '/filter.admin.js', + ), + '#attached_css' => array( + drupal_get_path('module', 'filter') . '/filter.css', + ), + ); + + $form['name'] = array( + '#type' => 'textfield', '#title' => t('Name'), '#default_value' => $format->name, '#description' => t('Specify a unique name for this text format.'), '#required' => TRUE, ); - // Add a row of checkboxes for form group. - $form['roles'] = array('#type' => 'fieldset', + // Add user role access selection. + $options = array(); + $defaults = array(); + foreach (user_roles() as $rid => $role_name) { + $options[$rid] = $role_name; + if ($default || strpos($format->roles, ",$rid,") !== FALSE) { + $defaults[$rid] = $rid; + } + } + $form['roles'] = array( + '#type' => 'checkboxes', '#title' => t('Roles'), '#description' => $default ? $help : t('Choose which roles may use this text format. Note that roles with the "administer filters" permission can always use all text formats.'), - '#tree' => TRUE, + '#options' => $options, + '#default_value' => $defaults, + '#disabled' => $default, ); - foreach (user_roles() as $rid => $name) { - $checked = strpos($format->roles, ",$rid,") !== FALSE; - $form['roles'][$rid] = array('#type' => 'checkbox', - '#title' => $name, - '#default_value' => ($default || $checked), - ); - if ($default) { - $form['roles'][$rid]['#disabled'] = TRUE; - } - } - // Table with filters + // Build a form to change the settings for filters in a text format. + // The form is built by merging the results of 'settings callback' for each + // enabled filter in the given format. $filter_info = filter_get_filters(); - $filters = filter_list_format($format->format); + $filters = filter_list_format($format->format, TRUE); - $form['filters'] = array('#type' => 'fieldset', - '#title' => t('Filters'), - '#description' => t('Choose the filters that will be used in this text format.'), - '#tree' => TRUE, + $form['filter_settings'] = array( + '#type' => 'vertical_tabs', ); + foreach ($filter_info as $name => $filter) { - $form['filters'][$name] = array( + $form['filters'][$name]['status'] = array( '#type' => 'checkbox', + '#default_value' => !empty($filters[$name]->status), '#title' => $filter['title'], - '#default_value' => isset($filters[$name]), '#description' => $filter['description'], ); - } + $form['filters'][$name]['weight'] = array( + '#type' => 'weight', + '#delta' => 50, + '#default_value' => 0, + ); + $form['filters'][$name]['settings'] = filter_filter_settings_form($form_state, $filters[$name], $filter_info[$name], $format, $filters); + } + if (!empty($format->format)) { - $form['format'] = array('#type' => 'hidden', '#value' => $format->format); + $form['format'] = array('#type' => 'value', '#value' => $format->format); // Composition tips (guidelines) $tips = _filter_tips($format->format, FALSE); @@ -180,6 +198,60 @@ return $form; } +function filter_filter_settings_form(&$form_state, $filter, $filter_info, $format, $filters) { + $form = array(); + if (isset($filter_info['settings callback']) && function_exists($filter_info['settings callback'])) { + // Pass along stored filter settings and default settings, but also the + // format object and all filters to allow for complex implementations. + $defaults = (isset($filter_info['default settings']) ? $filter_info['default settings'] : array()); + $settings_form = $filter_info['settings callback']($form_state, $filter, $defaults, $format, $filters); + if (isset($settings_form) && is_array($settings_form)) { + $form = array( + '#type' => 'fieldset', + '#title' => $filter_info['title'], + '#group' => 'filter_settings', + '#tree' => TRUE, + ); + $form += $settings_form; + } + } + return $form; +} + +/** + * Theme filter order configuration form. + * + * @ingroup themeable + */ +function theme_filter_admin_format_form($form) { + $header = array( + array('data' => t('Filter'), 'class' => array('checkbox')), + t('Weight'), + ); + + $rows = array(); + foreach (element_children($form['filters']) as $name) { + $form['filters'][$name]['weight']['#attributes']['class'] = array('filter-order-weight'); + $rows[] = array( + 'data' => array( + drupal_render($form['filters'][$name]['status']), + drupal_render($form['filters'][$name]['weight']), + ), + 'class' => array('draggable'), + ); + } + + $output = drupal_render($form['name']); + $output .= drupal_render($form['roles']); + $output .= theme('table', $header, $rows, array('id' => 'filter-order'), t('Choose the filters that will be used in this text format.')); + $output .= drupal_render($form['filter_settings']); + $output .= drupal_render_children($form); + + drupal_add_tabledrag('filter-order', 'order', 'sibling', 'filter-order-weight', NULL, NULL, TRUE); + + return $output; +} + /** * Validate text format form submissions. */ @@ -252,150 +324,3 @@ $form_state['redirect'] = 'admin/settings/formats'; } -/** - * Menu callback; display settings defined by a format's filters. - */ -function filter_admin_configure_page($format) { - drupal_set_title(t("Configure %format", array('%format' => $format->name)), PASS_THROUGH); - return drupal_get_form('filter_admin_configure', $format); -} - -/** - * Build a form to change the settings for filters in a text format. - * - * The form is built by merging the results of 'settings callback' for each - * enabled filter in the given format. - * - * @ingroup forms - */ -function filter_admin_configure(&$form_state, $format) { - $filters = filter_list_format($format->format); - $filter_info = filter_get_filters(); - - $form['#format'] = $format; - foreach ($filters as $name => $filter) { - if (isset($filter_info[$name]['settings callback']) && function_exists($filter_info[$name]['settings callback'])) { - // Pass along stored filter settings and default settings, but also the - // format object and all filters to allow for complex implementations. - $defaults = (isset($filter_info[$name]['default settings']) ? $filter_info[$name]['default settings'] : array()); - $settings_form = $filter_info[$name]['settings callback']($form_state, $filters[$name], $defaults, $format, $filters); - if (isset($settings_form) && is_array($settings_form)) { - $form['settings'][$name] = array( - '#type' => 'fieldset', - '#title' => check_plain($filter->title), - ); - $form['settings'][$name] += $settings_form; - } - } - } - - if (empty($form['settings'])) { - $form['error'] = array('#markup' => t('No settings are available.')); - return $form; - } - $form['settings']['#tree'] = TRUE; - $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); - - return $form; -} - -/** - * Form submit handler for text format filter configuration form. - * - * @see filter_admin_configure() - */ -function filter_admin_configure_submit($form, &$form_state) { - $format = $form['#format']; - - foreach ($form_state['values']['settings'] as $name => $settings) { - db_update('filter') - ->fields(array( - 'settings' => serialize($settings), - )) - ->condition('format', $format->format) - ->condition('name', $name) - ->execute(); - } - - // Clear the filter's cache when configuration settings are saved. - cache_clear_all($format->format . ':', 'cache_filter', TRUE); - - drupal_set_message(t('The configuration options have been saved.')); -} - -/** - * Menu callback; display form for ordering filters for a format. - */ -function filter_admin_order_page($format) { - drupal_set_title(t("Rearrange %format", array('%format' => $format->name)), PASS_THROUGH); - return drupal_get_form('filter_admin_order', $format); -} - -/** - * Build the form for ordering filters for a format. - * - * @ingroup forms - * @see theme_filter_admin_order() - * @see filter_admin_order_submit() - */ -function filter_admin_order(&$form_state, $format = NULL) { - // Get list (with forced refresh). - $filters = filter_list_format($format->format); - - $form['weights'] = array('#tree' => TRUE); - foreach ($filters as $id => $filter) { - $form['names'][$id] = array('#markup' => $filter->title); - $form['weights'][$id] = array('#type' => 'weight', '#default_value' => $filter->weight); - } - $form['format'] = array('#type' => 'hidden', '#value' => $format->format); - $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); - - return $form; -} - -/** - * Theme filter order configuration form. - * - * @ingroup themeable - */ -function theme_filter_admin_order($form) { - $header = array(t('Name'), t('Weight')); - $rows = array(); - foreach (element_children($form['names']) as $id) { - // Don't take form control structures. - if (is_array($form['names'][$id])) { - $form['weights'][$id]['#attributes']['class'] = array('filter-order-weight'); - $rows[] = array( - 'data' => array(drupal_render($form['names'][$id]), drupal_render($form['weights'][$id])), - 'class' => array('draggable'), - ); - } - } - - $output = theme('table', $header, $rows, array('id' => 'filter-order')); - $output .= drupal_render_children($form); - - drupal_add_tabledrag('filter-order', 'order', 'sibling', 'filter-order-weight', NULL, NULL, FALSE); - - return $output; -} - -/** - * Process filter order configuration form submission. - */ -function filter_admin_order_submit($form, &$form_state) { - foreach ($form_state['values']['weights'] as $name => $weight) { - db_merge('filter') - ->key(array( - 'format' => $form_state['values']['format'], - 'name' => $name, - )) - ->fields(array( - 'weight' => $weight, - )) - ->execute(); - } - drupal_set_message(t('The filter ordering has been saved.')); - - cache_clear_all($form_state['values']['format'] . ':', 'cache_filter', TRUE); -} Index: modules/filter/filter.css =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.css,v retrieving revision 1.1 diff -u -r1.1 filter.css --- modules/filter/filter.css 30 Mar 2009 03:15:40 -0000 1.1 +++ modules/filter/filter.css 28 Aug 2009 16:10:49 -0000 @@ -35,3 +35,11 @@ .text-format-wrapper .description { margin-top: 0.5em; } + +#filter-order tr .form-item { + padding: 0.5em 0 0 3em; + white-space: normal; +} +#filter-order tr .form-type-checkbox .description { + padding: 0 0 0 2.5em; +} Index: modules/filter/filter.admin.js =================================================================== RCS file: modules/filter/filter.admin.js diff -N modules/filter/filter.admin.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/filter/filter.admin.js 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,60 @@ +// $Id$ + +(function ($) { + +/** + * Displays the tab's content pane. + */ +Drupal.verticalTab.prototype.tabShow = function () { + this.item.show(); + this.fieldset.removeClass('element-hidden'); + this.focus(); + this.updateSummary(); +}; + +/** + * Displays the tab's content pane. + */ +Drupal.verticalTab.prototype.tabHide = function () { + this.item.hide(); + this.fieldset.addClass('element-hidden'); + var newtab = this.fieldset.siblings('fieldset.vertical-tabs-pane:not(.element-hidden):first') + .data('verticalTab') + .focus(); +}; + +Drupal.behaviors.filterFieldsetSummaries = { + attach: function (context, settings) { + // Process all fieldsets in the vertical tabs group. + // @todo There seems to be no way to attach a CSS id to target a specific + // vertical tabs group. + $('.vertical-tabs fieldset', context).each(function () { + // Retrieve the tab belonging to this fieldset. + var tab = $(this).data('verticalTab'); + var $checkbox = $('#' + tab.fieldset.attr('id').replace(/-settings$/, '-status'), context); + $checkbox.click(function () { + //var newtab = $('#' + this.id.replace(/-status$/, '-settings'), context).data('verticalTab'); + // Display filter settings. + if ($checkbox.is(':checked')) { + tab.tabShow(); + } + // Hide filter settings. + else { + tab.tabHide(); + } + }); + // Re-use the summary updater to update the tab. + tab.fieldset.setSummary(function (tabContext) { + if ($checkbox.is(':checked')) { + return Drupal.t('Enabled'); + } + else { + tab.tabHide(); + return Drupal.t('Disabled'); + } + }); + }); + } +}; + +})(jQuery);