Commit b5f5e750 authored by Dries's avatar Dries

- Patch #222183 by Gabor and Keith: make the input formats reorderable as a...

- Patch #222183 by Gabor and Keith: make the input formats reorderable as a first step towards better input format handling, and ultimately, good WYSIWYIG support.
parent 38e0ab1f
......@@ -2,7 +2,8 @@
Drupal 7.0, xxxx-xx-xx (development version)
----------------------
- Usability:
* Implemented drag-and-drop positioning for input format listings.
Drupal 6.0, 2008-02-13
----------------------
......
......@@ -19,6 +19,7 @@ function filter_admin_overview() {
$formats = filter_formats();
$error = FALSE;
$form = array('#tree' => TRUE);
foreach ($formats as $id => $format) {
$roles = array();
foreach (user_roles() as $rid => $name) {
......@@ -29,13 +30,14 @@ function filter_admin_overview() {
}
$default = ($id == variable_get('filter_default_format', 1));
$options[$id] = '';
$form[$format->name]['id'] = array('#value' => $id);
$form[$format->name]['roles'] = array('#value' => $default ? t('All roles may use default format') : ($roles ? implode(', ', $roles) : t('No roles may use this format')));
$form[$format->name]['configure'] = array('#value' => l(t('configure'), 'admin/settings/filters/'. $id));
$form[$format->name]['delete'] = array('#value' => $default ? '' : l(t('delete'), 'admin/settings/filters/delete/'. $id));
$form[$id]['name'] = array('#value' => $format->name);
$form[$id]['roles'] = array('#value' => $default ? t('All roles may use default format') : ($roles ? implode(', ', $roles) : t('No roles may use this format')));
$form[$id]['configure'] = array('#value' => l(t('configure'), 'admin/settings/filters/'. $id));
$form[$id]['delete'] = array('#value' => $default ? '' : l(t('delete'), 'admin/settings/filters/delete/'. $id));
$form[$id]['weight'] = array('#type' => 'weight', '#default_value' => $format->weight);
}
$form['default'] = array('#type' => 'radios', '#options' => $options, '#default_value' => variable_get('filter_default_format', 1));
$form['submit'] = array('#type' => 'submit', '#value' => t('Set default format'));
$form['submit'] = array('#type' => 'submit', '#value' => t('Save changes'));
return $form;
}
......@@ -45,6 +47,13 @@ function filter_admin_overview_submit($form, &$form_state) {
drupal_set_message(t('Default format updated.'));
variable_set('filter_default_format', $form_state['values']['default']);
}
foreach ($form_state['values'] as $id => $data) {
if (is_array($data) && isset($data['weight'])) {
// Only update if this is a form element with weight.
db_query("UPDATE {filter_formats} SET weight = %d WHERE format = %d", $data['weight'], $id);
}
}
drupal_set_message(t('The input format ordering has been saved.'));
}
/**
......@@ -54,22 +63,29 @@ function filter_admin_overview_submit($form, &$form_state) {
*/
function theme_filter_admin_overview($form) {
$rows = array();
foreach ($form as $name => $element) {
foreach ($form as $id => $element) {
if (isset($element['roles']) && is_array($element['roles'])) {
$element['weight']['#attributes']['class'] = 'input-format-order-weight';
$rows[] = array(
drupal_render($form['default'][$element['id']['#value']]),
check_plain($name),
drupal_render($element['roles']),
drupal_render($element['configure']),
drupal_render($element['delete'])
'data' => array(
check_plain($element['name']['#value']),
drupal_render($element['roles']),
drupal_render($form['default'][$id]),
drupal_render($element['weight']),
drupal_render($element['configure']),
drupal_render($element['delete']),
),
'class' => 'draggable',
);
unset($form[$name]);
unset($form[$id]);
}
}
$header = array(t('Default'), t('Name'), t('Roles'), array('data' => t('Operations'), 'colspan' => 2));
$output = theme('table', $header, $rows);
$header = array(t('Name'), t('Roles'), t('Default'), t('Weight'), array('data' => t('Operations'), 'colspan' => 2));
$output = theme('table', $header, $rows, array('id' => 'input-format-order'));
$output .= drupal_render($form);
drupal_add_tabledrag('input-format-order', 'order', 'sibling', 'input-format-order-weight');
return $output;
}
......
......@@ -78,6 +78,13 @@ function filter_schema() {
'size' => 'tiny',
'description' => t('Flag to indicate whether format is cachable. (1 = cachable, 0 = not cachable)'),
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => t('Weight of input format to use when listing.'),
)
),
'primary key' => array('format'),
'unique keys' => array('name' => array('name')),
......@@ -89,3 +96,11 @@ function filter_schema() {
return $schema;
}
/**
* Add a weight column to the filter formats table.
*/
function filter_update_7000() {
$ret = array();
db_add_field($ret, 'filter_formats', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
return $ret;
}
......@@ -22,12 +22,12 @@ function filter_help($path, $arg) {
case 'admin/help#filter':
$output = '<p>'. t("The filter module allows administrators to configure text input formats for use on your site. An input format defines the HTML tags, codes, and other input allowed in both content and comments, and is a key feature in guarding against potentially damaging input from malicious users. Two input formats included by default are <em>Filtered HTML</em> (which allows only an administrator-approved subset of HTML tags) and <em>Full HTML</em> (which allows the full set of HTML tags). Additional input formats may be created by an administrator.") .'</p>';
$output .= '<p>'. t('Each input format uses filters to manipulate text, and most input formats apply several different filters to text in a specific order. Each filter is designed for a specific purpose, and generally either adds, removes or transforms elements within user-entered text before it is displayed. A filter does not change the actual content of a post, but instead, modifies it temporarily before it is displayed. A filter may remove unapproved HTML tags, for instance, while another automatically adds HTML to make links referenced in text clickable.') .'</p>';
$output .= '<p>'. t('Users can choose between the available input formats when creating or editing content. Administrators can configure which input formats are available to which user roles, as well as choose a default input format.') .'</p>';
$output .= '<p>'. t('Users with access to more than one input format can use the <em>Input format</em> fieldset to choose between available input formats when creating or editing multi-line content. Administrators determine the input formats available to each user role, select a default input format, and control the order of formats listed in the <em>Input format</em> fieldset.') .'</p>';
$output .= '<p>'. t('For more information, see the online handbook entry for <a href="@filter">Filter module</a>.', array('@filter' => 'http://drupal.org/handbook/modules/filter/')) .'</p>';
return $output;
case 'admin/settings/filters':
$output = '<p>'. t('<em>Input formats</em> define a way of processing user-supplied text in Drupal. Each input format uses filters to manipulate text, and most input formats apply several different filters to text, in a specific order. Each filter is designed to accomplish a specific purpose, and generally either removes elements from or adds elements to text before it is displayed. Users can choose between the available input formats when submitting content.') .'</p>';
$output .= '<p>'. t('Use the list below to configure which input formats are available to which roles, as well as choose a default input format (used for imported content, for example). The default format is always available to users. All input formats are available to users in a role with the "administer filters" permission.') .'</p>';
$output = '<p>'. t('Use the list below to review the input formats available to each user role, to select a default input format, and to control the order of formats listed in the <em>Input format</em> fieldset. (The <em>Input format</em> fieldset is displayed below textareas when users with access to more than one input format create multi-line content.) The input format selected as <em>Default</em> is available to all users and, unless another format is selected, is applied to all content. All input formats are available to users in roles with the "administer filters" permission.') .'</p>';
$output .= '<p>'. t('Since input formats, if available, are presented in the same order as the list below, it may be helpful to arrange the formats in descending order of your preference for their use. To change the order of an input format, grab a drag-and-drop handle under the <em>Name</em> column and drag to a new location in the list. (Grab a handle by clicking and holding the mouse while hovering over a handle icon.) Remember that your changes will not be saved until you click the <em>Save changes</em> button at the bottom of the page.') .'</p>';
return $output;
case 'admin/settings/filters/%':
return '<p>'. t('Every <em>filter</em> performs one particular change on the user input, for example stripping out malicious HTML or making URLs clickable. Choose which filters you want to apply to text in this input format. If you notice some filters are causing conflicts in the output, you can <a href="@rearrange">rearrange them</a>.', array('@rearrange' => url('admin/settings/filters/'. $arg[3] .'/order'))) .'</p>';
......@@ -308,7 +308,7 @@ function filter_formats($index = NULL) {
$args[] = variable_get('filter_default_format', 1);
}
$result = db_query($query, $args);
$result = db_query($query .' ORDER by weight', $args);
while ($format = db_fetch_object($result)) {
$formats[$format->format] = $format;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment