diff --git a/core/modules/filter/filter.admin.inc b/core/modules/filter/filter.admin.inc index 4cc4a1f..ff98056 100644 --- a/core/modules/filter/filter.admin.inc +++ b/core/modules/filter/filter.admin.inc @@ -189,20 +189,13 @@ function filter_admin_format_form($form, &$form_state, $format) { // Retrieve available filters and load all configured filters for existing // text formats. - $filter_info = filter_get_filters(); $filters = !empty($format->format) ? filter_list_format($format->format) : array(); // Prepare filters for form sections. - foreach ($filter_info as $name => $filter) { + foreach (array_keys($format->filterPlugins->getInstanceIDs()) as $name) { // Create an empty filter object for new/unconfigured filters. if (!isset($filters[$name])) { - $filters[$name] = new stdClass(); - $filters[$name]->format = $format->format; - $filters[$name]->module = $filter['module']; - $filters[$name]->name = $name; - $filters[$name]->status = 0; - $filters[$name]->weight = $filter['weight']; - $filters[$name]->settings = array(); + $filters[$name] = $format->filterPlugins->get($name); } } $form['#filters'] = $filters; @@ -218,16 +211,6 @@ function filter_admin_format_form($form, &$form_state, $format) { // @see http://drupal.org/node/1829202 '#input' => FALSE, ); - foreach ($filter_info as $name => $filter) { - $form['filters']['status'][$name] = array( - '#type' => 'checkbox', - '#title' => $filter['title'], - '#default_value' => $filters[$name]->status, - '#parents' => array('filters', $name, 'status'), - '#description' => $filter['description'], - '#weight' => $filter['weight'], - ); - } // Filter order (tabledrag). $form['filters']['order'] = array( @@ -239,43 +222,48 @@ function filter_admin_format_form($form, &$form_state, $format) { // @see http://drupal.org/node/1829202 '#input' => FALSE, ); - foreach ($filter_info as $name => $filter) { + + // Filter settings. + $form['filter_settings'] = array( + '#type' => 'vertical_tabs', + '#title' => t('Filter settings'), + ); + + foreach ($filters as $name => $filter) { + $form['filters']['status'][$name] = array( + '#type' => 'checkbox', + '#title' => $filter->title, + '#default_value' => $filter->status, + '#parents' => array('filters', $name, 'status'), + '#description' => $filter->description, + '#weight' => $filter->weight, + ); + $form['filters']['order'][$name]['filter'] = array( - '#markup' => $filter['title'], + '#markup' => $filter->title, ); $form['filters']['order'][$name]['weight'] = array( '#type' => 'weight', - '#title' => t('Weight for @title', array('@title' => $filter['title'])), + '#title' => t('Weight for @title', array('@title' => $filter->title)), '#title_display' => 'invisible', '#delta' => 50, - '#default_value' => $filters[$name]->weight, + '#default_value' => $filter->weight, '#parents' => array('filters', $name, 'weight'), ); - $form['filters']['order'][$name]['#weight'] = $filters[$name]->weight; - } - - // Filter settings. - $form['filter_settings'] = array( - '#type' => 'vertical_tabs', - '#title' => t('Filter settings'), - ); - - foreach ($filter_info as $name => $filter) { - if (isset($filter['settings callback'])) { - $function = $filter['settings callback']; - // Pass along stored filter settings and default settings, but also the - // format object and all filters to allow for complex implementations. - $settings_form = $function($form, $form_state, $filters[$name], $format, $filter['default settings'], $filters); - if (!empty($settings_form)) { - $form['filters']['settings'][$name] = array( - '#type' => 'details', - '#title' => $filter['title'], - '#parents' => array('filters', $name, 'settings'), - '#weight' => $filter['weight'], - '#group' => 'filter_settings', - ); - $form['filters']['settings'][$name] += $settings_form; - } + $form['filters']['order'][$name]['#weight'] = $filter->weight; + + // Pass along stored filter settings and default settings, but also the + // format object and all filters to allow for complex implementations. + $settings_form = $filter->settingsForm($form, $form_state); + if (!empty($settings_form)) { + $form['filters']['settings'][$name] = array( + '#type' => 'details', + '#title' => $filter->title, + '#parents' => array('filters', $name, 'settings'), + '#weight' => $filter->weight, + '#group' => 'filter_settings', + ); + $form['filters']['settings'][$name] += $settings_form; } } diff --git a/core/modules/filter/filter.api.php b/core/modules/filter/filter.api.php index c041eb4..8d6aa01 100644 --- a/core/modules/filter/filter.api.php +++ b/core/modules/filter/filter.api.php @@ -11,272 +11,19 @@ */ /** - * Define content filters. - * - * User submitted content is passed through a group of filters before it is - * output in HTML, in order to remove insecure or unwanted parts, correct or - * enhance the formatting, transform special keywords, etc. A group of filters - * is referred to as a "text format". Administrators can create as many text - * formats as needed. Individual filters can be enabled and configured - * differently for each text format. - * - * This hook is invoked by filter_get_filters() and allows modules to register - * input filters they provide. - * - * Filtering is a two-step process. First, the content is 'prepared' by calling - * the 'prepare callback' function for every filter. The purpose of the - * 'prepare callback' is to escape HTML-like structures. For example, imagine a - * filter which allows the user to paste entire chunks of programming code - * without requiring manual escaping of special HTML characters like < or &. If - * the programming code were left untouched, then other filters could think it - * was HTML and change it. For many filters, the prepare step is not necessary. - * - * The second step is the actual processing step. The result from passing the - * text through all the filters' prepare steps gets passed to all the filters - * again, this time with the 'process callback' function. The process callbacks - * should then actually change the content: transform URLs into hyperlinks, - * convert smileys into images, etc. - * - * For performance reasons content is only filtered once; the result is stored - * in the cache table and retrieved from the cache the next time the same piece - * of content is displayed. If a filter's output is dynamic, it can override - * the cache mechanism, but obviously this should be used with caution: having - * one filter that does not support caching in a particular text format - * disables caching for the entire format, not just for one filter. - * - * Beware of the filter cache when developing your module: it is advised to set - * your filter to 'cache' => FALSE while developing, but be sure to remove that - * setting if it's not needed, when you are no longer in development mode. - * - * @return - * An associative array of filters, whose keys are internal filter names, - * which should be unique and therefore prefixed with the name of the module. - * Each value is an associative array describing the filter, with the - * following elements (all are optional except as noted): - * - title: (required) An administrative summary of what the filter does. - * - description: Additional administrative information about the filter's - * behavior, if needed for clarification. - * - settings callback: The name of a function that returns configuration - * form elements for the filter. See hook_filter_FILTER_settings() for - * details. - * - default settings: An associative array containing default settings for - * the filter, to be applied when the filter has not been configured yet. - * - prepare callback: The name of a function that escapes the content before - * the actual filtering happens. See hook_filter_FILTER_prepare() for - * details. - * - process callback: (required) The name the function that performs the - * actual filtering. See hook_filter_FILTER_process() for details. - * - cache (default TRUE): Specifies whether the filtered text can be cached. - * Note that setting this to FALSE makes the entire text format not - * cacheable, which may have an impact on the site's overall performance. - * See filter_format_allowcache() for details. - * - tips callback: The name of a function that returns end-user-facing - * filter usage guidelines for the filter. See hook_filter_FILTER_tips() - * for details. - * - weight: A default weight for the filter in new text formats. - * - * @see filter_example.module - * @see hook_filter_info_alter() - */ -function hook_filter_info() { - $filters['filter_html'] = array( - 'title' => t('Limit allowed HTML tags'), - 'description' => t('Allows you to restrict the HTML tags the user can use. It will also remove harmful content such as JavaScript events, JavaScript URLs and CSS styles from those tags that are not removed.'), - 'process callback' => '_filter_html', - 'settings callback' => '_filter_html_settings', - 'default settings' => array( - 'allowed_html' => '