Commit 6764b73f authored by Dries's avatar Dries

- Patch #570930 by sun: allow to retrieve all filters (including disabled) in a text format.

parent 5e590b9e
......@@ -118,7 +118,8 @@ function filter_admin_format_form(&$form_state, $format) {
$form['default_format'] = array('#type' => 'hidden', '#value' => 1);
}
$form['name'] = array('#type' => 'textfield',
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $format->name,
'#description' => t('Specify a unique name for this text format.'),
......@@ -144,7 +145,7 @@ function filter_admin_format_form(&$form_state, $format) {
}
// Table with filters
$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'),
......@@ -152,10 +153,10 @@ function filter_admin_format_form(&$form_state, $format) {
'#tree' => TRUE,
);
foreach ($filter_info as $name => $filter) {
$form['filters'][$name] = array(
$form['filters'][$name]['status'] = array(
'#type' => 'checkbox',
'#title' => $filter['title'],
'#default_value' => isset($filters[$name]),
'#default_value' => !empty($filters[$name]->status),
'#description' => $filter['description'],
);
}
......
......@@ -70,6 +70,13 @@ function filter_theme() {
* 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/config/content/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 +97,6 @@ function filter_menu() {
'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/config/content/formats/%filter_format'] = array(
'type' => MENU_CALLBACK,
'title callback' => 'filter_admin_format_title',
......@@ -185,15 +185,14 @@ function filter_format_save($format) {
// 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 +210,8 @@ function filter_format_save($format) {
module_invoke_all('filter_format_update', $format);
}
// Clear the filter cache whenever a text format is saved.
drupal_static_reset('filter_list_format');
cache_clear_all($format->format . ':', 'cache_filter', TRUE);
return $return;
......@@ -386,6 +387,7 @@ function _filter_html_escape_tips($filter, $format, $long = FALSE) {
/**
* @} End of "Tips callback for filters".
*/
/**
* Retrieve a list of text formats.
*/
......@@ -472,47 +474,52 @@ function filter_format_allowcache($format) {
}
/**
* Retrieve a list of filters for a certain format.
* Retrieve a list of filters for a given text format.
*
* @param $format
* The format ID.
* @param $include_disabled
* (optional) Boolean whether to retrieve all filters associated with the
* given format, including those that are disabled. Defaults to FALSE.
* @return
* An array of filter objects assosiated to the given format.
*/
function filter_list_format($format) {
static $filters = array();
function filter_list_format($format, $include_disabled = FALSE) {
$filters = &drupal_static(__FUNCTION__, array());
$filter_info = filter_get_filters();
if (!isset($filters[$format])) {
$filters[$format] = array();
$result = db_select('filter', 'filter')
if (!isset($filters[$format]) || $include_disabled) {
$format_filters = array();
$query = db_select('filter', 'filter')
->fields('filter')
->condition('format', $format)
->condition('status', 1)
->orderBy('weight')
->orderBy('module')
->orderBy('name')
->execute();
foreach ($result as $filter) {
if (isset($filter_info[$filter->name])) {
$filter->title = $filter_info[$filter->name]['title'];
->orderBy('name');
if (!$include_disabled) {
$query->condition('status', 1);
}
$result = $query->execute()->fetchAllAssoc('name');
foreach ($result as $name => $filter) {
if (isset($filter_info[$name])) {
$filter->title = $filter_info[$name]['title'];
// Unpack stored filter settings.
if (isset($filter->settings)) {
$filter->settings = unserialize($filter->settings);
}
else {
$filter->settings = array();
}
$filter->settings = (isset($filter->settings) ? unserialize($filter->settings) : array());
// Apply default filter settings.
if (isset($filter_info[$filter->name]['default settings'])) {
$filter->settings = array_merge($filter_info[$filter->name]['default settings'], $filter->settings);
if (isset($filter_info[$name]['default settings'])) {
$filter->settings = array_merge($filter_info[$name]['default settings'], $filter->settings);
}
$filters[$format][$filter->name] = $filter;
$format_filters[$name] = $filter;
}
}
// Prevent statically caching of disabled filters.
if ($include_disabled) {
return $format_filters;
}
$filters[$format] = $format_filters;
}
return $filters[$format];
return isset($filters[$format]) ? $filters[$format] : array();
}
/**
......
......@@ -65,8 +65,8 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$edit = array();
$edit['name'] = $this->randomName();
$edit['roles[2]'] = 1;
$edit['filters[' . $second_filter . ']'] = TRUE;
$edit['filters[' . $first_filter . ']'] = TRUE;
$edit['filters[' . $second_filter . '][status]'] = TRUE;
$edit['filters[' . $first_filter . '][status]'] = TRUE;
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
$this->assertRaw(t('Added text format %format.', array('%format' => $edit['name'])), t('New filter created.'));
......@@ -75,8 +75,8 @@ class FilterAdminTestCase extends DrupalWebTestCase {
if ($format !== NULL) {
$this->assertFieldByName('roles[2]', '', t('Role found.'));
$this->assertFieldByName('filters[' . $second_filter . ']', '', t('Line break filter found.'));
$this->assertFieldByName('filters[' . $first_filter . ']', '', t('Url filter found.'));
$this->assertFieldByName('filters[' . $second_filter . '][status]', '', t('Line break filter found.'));
$this->assertFieldByName('filters[' . $first_filter . '][status]', '', t('Url filter found.'));
// Delete new filter.
$this->drupalPost('admin/config/content/formats/' . $format->format . '/delete', array(), t('Delete'));
......
......@@ -538,14 +538,13 @@ function forum_block_view($delta = '') {
break;
}
$cache_keys[] = 'forum';
$cache_keys[] = $delta;
// Cache based on the altered query. Enables us to cache with node access enabled.
$query->preExecute();
$cache_keys[] = md5(serialize(array((string) $query, $query->getArguments())));
$block['subject'] = $title;
$block['content'] = array(
$cache_keys = array_merge(array('forum', $delta), drupal_render_cid_parts());
// Cache based on the altered query. Enables us to cache with node access enabled.
$query->preExecute();
$cache_keys[] = md5(serialize(array((string) $query, $query->getArguments())));
$block['subject'] = $title;
$block['content'] = array(
'#access' => user_access('access content'),
'#pre_render' => array('forum_block_view_pre_render'),
'#cache' => array(
......@@ -553,8 +552,8 @@ function forum_block_view($delta = '') {
'expire' => CACHE_TEMPORARY,
),
'#query' => $query,
);
return $block;
);
return $block;
}
/**
......
......@@ -471,7 +471,7 @@ class SearchCommentTestCase extends DrupalWebTestCase {
variable_set('comment_preview_article', COMMENT_PREVIEW_OPTIONAL);
// Enable check_plain() for 'Filtered HTML' text format.
$edit = array(
'filters[filter_html_escape]' => 1,
'filters[filter_html_escape][status]' => 1,
);
$this->drupalPost('admin/config/content/formats/1', $edit, t('Save configuration'));
// Allow anonymous users to search content.
......
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