diff --git a/modules/field/modules/text/text.module b/modules/field/modules/text/text.module
index 7af5d34fa70..914494256f2 100644
--- a/modules/field/modules/text/text.module
+++ b/modules/field/modules/text/text.module
@@ -398,7 +398,7 @@ function text_summary($text, $format = NULL, $size = NULL) {
// parse errors.
if (isset($format)) {
$filters = filter_list_format($format);
- if (isset($filters['php/php_code']) && strpos($text, '') !== FALSE) {
+ if (isset($filters['php_code']) && strpos($text, '') !== FALSE) {
return $text;
}
}
@@ -437,7 +437,7 @@ function text_summary($text, $format = NULL, $size = NULL) {
$line_breaks = array('
' => 6, '
' => 4);
// Newline only indicates a line break if line break converter
// filter is present.
- if (isset($filters['filter/filter_autop'])) {
+ if (isset($filters['filter_autop'])) {
$line_breaks["\n"] = 1;
}
$break_points[] = $line_breaks;
@@ -465,7 +465,7 @@ function text_summary($text, $format = NULL, $size = NULL) {
}
// If the htmlcorrector filter is present, apply it to the generated summary.
- if (isset($filters['filter/filter_htmlcorrector'])) {
+ if (isset($filters['filter_htmlcorrector'])) {
$summary = _filter_htmlcorrector($summary);
}
diff --git a/modules/filter/filter.admin.inc b/modules/filter/filter.admin.inc
index 6f32577571c..e3210e4ec34 100644
--- a/modules/filter/filter.admin.inc
+++ b/modules/filter/filter.admin.inc
@@ -143,7 +143,7 @@ function filter_admin_format_form(&$form_state, $format) {
}
}
// Table with filters
- $all = filter_list_all();
+ $filter_info = filter_get_filters();
$enabled = filter_list_format($format->format);
$form['filters'] = array('#type' => 'fieldset',
@@ -151,12 +151,12 @@ function filter_admin_format_form(&$form_state, $format) {
'#description' => t('Choose the filters that will be used in this text format.'),
'#tree' => TRUE,
);
- foreach ($all as $id => $filter) {
- $filter_info = module_invoke($filter->module, 'filter_info');
- $form['filters'][$id] = array('#type' => 'checkbox',
- '#title' => $filter->title,
- '#default_value' => isset($enabled[$id]),
- '#description' => $filter_info[$filter->name]['description'],
+ foreach ($filter_info as $name => $filter) {
+ $form['filters'][$name] = array(
+ '#type' => 'checkbox',
+ '#title' => $filter['title'],
+ '#default_value' => isset($enabled[$name]),
+ '#description' => $filter['description'],
);
}
if (!empty($format->format)) {
@@ -185,8 +185,8 @@ function filter_admin_format_form(&$form_state, $format) {
*/
function filter_admin_format_form_validate($form, &$form_state) {
if (!isset($form_state['values']['format'])) {
- $name = trim($form_state['values']['name']);
- $result = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchField();
+ $format_name = trim($form_state['values']['name']);
+ $result = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $format_name))->fetchField();
if ($result) {
form_set_error('name', t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name)));
}
@@ -199,17 +199,17 @@ function filter_admin_format_form_validate($form, &$form_state) {
function filter_admin_format_form_submit($form, &$form_state) {
$format = isset($form_state['values']['format']) ? $form_state['values']['format'] : NULL;
$current = filter_list_format($format);
- $name = trim($form_state['values']['name']);
+ $format_name = trim($form_state['values']['name']);
$cache = TRUE;
// Add a new text format.
if (!$format) {
$new = TRUE;
db_insert('filter_format')
- ->fields(array('name' => $name))
+ ->fields(array('name' => $format_name))
->execute();
$format = db_query("SELECT MAX(format) AS format FROM {filter_format}")->fetchField();
- drupal_set_message(t('Added text format %format.', array('%format' => $name)));
+ drupal_set_message(t('Added text format %format.', array('%format' => $format_name)));
}
else {
drupal_set_message(t('The text format settings have been updated.'));
@@ -217,20 +217,16 @@ function filter_admin_format_form_submit($form, &$form_state) {
db_delete('filter')
->condition('format', $format)
->execute();
- $query = db_insert('filter')->fields(array('format', 'module', 'name', 'weight'));
- foreach ($form_state['values']['filters'] as $id => $checked) {
+ $query = db_insert('filter')->fields(array('format', 'name', 'weight'));
+ foreach ($form_state['values']['filters'] as $name => $checked) {
if ($checked) {
- list($module, $filter_name) = explode('/', $id);
// Add new filters to the bottom.
- $weight = isset($current[$id]->weight) ? $current[$id]->weight : 10;
+ $weight = isset($current[$name]->weight) ? $current[$name]->weight : 10;
$query->values(array(
'format' => $format,
- 'module' => $module,
- 'name' => $filter_name,
+ 'name' => $name,
'weight' => $weight,
));
- // Check if there are any 'no cache' filters.
- $cache &= !module_invoke($module, 'filter', 'no cache', $filter_name);
}
$query->execute();
}
@@ -256,7 +252,7 @@ function filter_admin_format_form_submit($form, &$form_state) {
db_update('filter_format')
->fields(array(
'cache' => $cache,
- 'name' => $name,
+ 'name' => $format_name,
'roles' => $roles,
))
->condition('format', $format)
@@ -349,11 +345,11 @@ function filter_admin_configure_page($format) {
*/
function filter_admin_configure(&$form_state, $format) {
$list = filter_list_format($format->format);
+ $filter_info = filter_get_filters();
$form = array();
- foreach ($list as $filter) {
- $filter_info = module_invoke($filter->module, 'filter_info');
- if (isset($filter_info[$filter->name]['settings callback']) && function_exists($filter_info[$filter->name]['settings callback'])) {
- $form_module = call_user_func($filter_info[$filter->name]['settings callback'], $format->format);
+ foreach ($list as $name => $filter) {
+ if (isset($filter_info[$name]['settings callback']) && function_exists($filter_info[$name]['settings callback'])) {
+ $form_module = call_user_func($filter_info[$name]['settings callback'], $format->format);
}
if (isset($form_module) && is_array($form_module)) {
$form = array_merge($form, $form_module);
@@ -399,7 +395,7 @@ function filter_admin_order(&$form_state, $format = NULL) {
$form['weights'] = array('#tree' => TRUE);
foreach ($filters as $id => $filter) {
- $form['names'][$id] = array('#markup' => $filter->name);
+ $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);
@@ -439,12 +435,10 @@ function theme_filter_admin_order($form) {
* Process filter order configuration form submission.
*/
function filter_admin_order_submit($form, &$form_state) {
- foreach ($form_state['values']['weights'] as $id => $weight) {
- list($module, $name) = explode('/', $id);
+ foreach ($form_state['values']['weights'] as $name => $weight) {
db_update('filter')
->fields(array('weight' => $weight))
->condition('format', $form_state['values']['format'])
- ->condition('module', $module)
->condition('name', $name)
->execute();
}
diff --git a/modules/filter/filter.api.php b/modules/filter/filter.api.php
index 8459c818871..0e118d51e1b 100644
--- a/modules/filter/filter.api.php
+++ b/modules/filter/filter.api.php
@@ -103,6 +103,19 @@ function hook_filter_info() {
);
}
+/**
+ * Perform alterations on filter definitions.
+ *
+ * @param $info
+ * Array of information on filters exposed by hook_filter_info()
+ * implementations.
+ */
+function hook_filter_info_alter(&$info) {
+ // Replace the PHP evaluator process callback with an improved
+ // PHP evaluator provided by a module.
+ $info['php_code']['process callback'] = 'my_module_php_evaluator';
+}
+
/**
* @} End of "addtogroup hooks".
*/
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index aaf2ac7a006..22c94dc701e 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -332,25 +332,23 @@ function filter_formats($index = NULL) {
}
/**
- * Build a list of all filters.
+ * Return a list of all filters provided by modules.
*/
-function filter_list_all() {
- $filters = array();
+function filter_get_filters() {
+ $filters = &drupal_static(__FUNCTION__, array());
- foreach (module_implements('filter_info') as $module) {
- $function = $module . '_filter_info';
- $info = $function('list');
- if (isset($info) && is_array($info)) {
- foreach ($info as $name => $filter) {
- $filters[$module . '/' . $name] = (object)($filter + array(
- 'module' => $module,
- 'name' => $name,
- ));
+ if (empty($filters)) {
+ foreach (module_implements('filter_info') as $module) {
+ $info = module_invoke($module, 'filter_info');
+ if (isset($info) && is_array($info)) {
+ $filters = array_merge($filters, $info);
}
}
- }
+ // Allow modules to alter filter definitions.
+ drupal_alter('filter_info', $filters);
- uasort($filters, '_filter_list_cmp');
+ uasort($filters, '_filter_list_cmp');
+ }
return $filters;
}
@@ -359,7 +357,7 @@ function filter_list_all() {
* Helper function for sorting the filter list by filter name.
*/
function _filter_list_cmp($a, $b) {
- return strcmp($a->name, $b->name);
+ return strcmp($a['title'], $b['title']);
}
/**
@@ -385,15 +383,15 @@ function filter_format_allowcache($format) {
*/
function filter_list_format($format) {
static $filters = array();
+ $filter_info = filter_get_filters();
if (!isset($filters[$format])) {
$filters[$format] = array();
$result = db_query("SELECT * FROM {filter} WHERE format = :format ORDER BY weight, module, name", array(':format' => (int) $format));
foreach ($result as $filter) {
- $info = module_invoke($filter->module, 'filter_info');
- if (isset($info) && is_array($info) && isset($info[$filter->name])) {
- $filter->title = $info[$filter->name]['title'];
- $filters[$format][$filter->module . '/' . $filter->name] = $filter;
+ if (isset($filter_info[$filter->name])) {
+ $filter->title = $filter_info[$filter->name]['title'];
+ $filters[$format][$filter->name] = $filter;
}
}
}
@@ -448,20 +446,19 @@ function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $langcode = '', $c
// Get a complete list of filters, ordered properly.
$filters = filter_list_format($format);
+ $filter_info = filter_get_filters();
// Give filters the chance to escape HTML-like data such as code or formulas.
- foreach ($filters as $filter) {
- $filter_info = module_invoke($filter->module, 'filter_info');
- if (isset($filter_info[$filter->name]['prepare callback']) && function_exists($filter_info[$filter->name]['prepare callback'])) {
- $text = call_user_func($filter_info[$filter->name]['prepare callback'], $text, $format, $langcode, $cache_id);
+ foreach ($filters as $name => $filter) {
+ if (isset($filter_info[$name]['prepare callback']) && function_exists($filter_info[$name]['prepare callback'])) {
+ $text = call_user_func($filter_info[$name]['prepare callback'], $text, $format, $langcode, $cache_id);
}
}
// Perform filtering.
- foreach ($filters as $filter) {
- $filter_info = module_invoke($filter->module, 'filter_info');
- if (isset($filter_info[$filter->name]['process callback']) && function_exists($filter_info[$filter->name]['process callback'])) {
- $text = call_user_func($filter_info[$filter->name]['process callback'], $text, $format, $langcode, $cache_id);
+ foreach ($filters as $name => $filter) {
+ if (isset($filter_info[$name]['process callback']) && function_exists($filter_info[$name]['process callback'])) {
+ $text = call_user_func($filter_info[$name]['process callback'], $text, $format, $langcode, $cache_id);
}
}
@@ -554,6 +551,7 @@ function filter_access($format) {
*/
function _filter_tips($format, $long = FALSE) {
$formats = filter_formats();
+ $filter_info = filter_get_filters();
$tips = array();
@@ -564,13 +562,11 @@ function _filter_tips($format, $long = FALSE) {
foreach ($formats as $format) {
$filters = filter_list_format($format->format);
-
$tips[$format->name] = array();
- foreach ($filters as $id => $filter) {
- $filter_info = module_invoke($filter->module, 'filter_info');
- if (isset($filter_info[$filter->name]['tips callback']) && function_exists($filter_info[$filter->name]['tips callback'])) {
- $tip = call_user_func($filter_info[$filter->name]['tips callback'],$format->format, $long);
- $tips[$format->name][] = array('tip' => $tip, 'id' => $id);
+ foreach ($filters as $name => $filter) {
+ if (isset($filter_info[$name]['tips callback']) && function_exists($filter_info[$name]['tips callback'])) {
+ $tip = call_user_func($filter_info[$name]['tips callback'],$format->format, $long);
+ $tips[$format->name][] = array('tip' => $tip, 'id' => $name);
}
}
}
diff --git a/modules/filter/filter.test b/modules/filter/filter.test
index af74fcfa25b..24157e4505a 100644
--- a/modules/filter/filter.test
+++ b/modules/filter/filter.test
@@ -47,8 +47,8 @@ class FilterAdminTestCase extends DrupalWebTestCase {
// Reorder filters.
$edit = array();
- $edit['weights[filter/' . $second_filter . ']'] = 1;
- $edit['weights[filter/' . $first_filter . ']'] = 2;
+ $edit['weights[' . $second_filter . ']'] = 1;
+ $edit['weights[' . $first_filter . ']'] = 2;
$this->drupalPost('admin/settings/formats/' . $filtered . '/order', $edit, t('Save configuration'));
$this->assertText(t('The filter ordering has been saved.'), t('Order saved successfully.'));
@@ -65,8 +65,8 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$edit = array();
$edit['name'] = $this->randomName();
$edit['roles[2]'] = TRUE;
- $edit['filters[filter/' . $second_filter . ']'] = TRUE;
- $edit['filters[filter/' . $first_filter . ']'] = TRUE;
+ $edit['filters[' . $second_filter . ']'] = TRUE;
+ $edit['filters[' . $first_filter . ']'] = TRUE;
$this->drupalPost('admin/settings/formats/add', $edit, t('Save configuration'));
$this->assertRaw(t('Added text format %format.', array('%format' => $edit['name'])), t('New filter created.'));
@@ -74,10 +74,9 @@ class FilterAdminTestCase extends DrupalWebTestCase {
$this->assertNotNull($format, t('Format found in database.'));
if ($format !== NULL) {
- debug($format);
$this->assertFieldByName('roles[2]', '', t('Role found.'));
- $this->assertFieldByName('filters[filter/' . $second_filter . ']', '', t('Line break filter found.'));
- $this->assertFieldByName('filters[filter/' . $first_filter . ']', '', t('Url filter found.'));
+ $this->assertFieldByName('filters[' . $second_filter . ']', '', t('Line break filter found.'));
+ $this->assertFieldByName('filters[' . $first_filter . ']', '', t('Url filter found.'));
// Delete new filter.
$this->drupalPost('admin/settings/formats/delete/' . $format->format, array(), t('Delete'));
@@ -142,8 +141,8 @@ class FilterAdminTestCase extends DrupalWebTestCase {
// Filter order.
$edit = array();
- $edit['weights[filter/' . $second_filter . ']'] = 2;
- $edit['weights[filter/' . $first_filter . ']'] = 1;
+ $edit['weights[' . $second_filter . ']'] = 2;
+ $edit['weights[' . $first_filter . ']'] = 1;
$this->drupalPost('admin/settings/formats/' . $filtered . '/order', $edit, t('Save configuration'));
$this->assertText(t('The filter ordering has been saved.'), t('Order successfully reverted.'));
}
diff --git a/modules/search/search.test b/modules/search/search.test
index 329937dd0a3..c81759a9766 100644
--- a/modules/search/search.test
+++ b/modules/search/search.test
@@ -461,7 +461,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/filter_html_escape]' => 1,
+ 'filters[filter_html_escape]' => 1,
);
$this->drupalPost('admin/settings/formats/1', $edit, t('Save configuration'));
// Allow anonymous users to search content.