Remove the concept of numeric deltas and use unique filters' names to declare and identify filters. Instead of using hardcoded numeric deltas and $module/$delta pairs to reference filters, an unique name, namespaced in the module that provides the filter should be used.

See #216072: DROP Task: Remove hardcoded numeric deltas from all hook_block() implementations in core for reference.

Example:

function filter_filter_info() {
  $filters['filter_html'] = array(
    'name' => 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',
    'tips callback'  => '_filter_html_tips'
  );
  $filters['filter_autop'] = array(
    'name' => t('Convert line breaks'),
    'description' => t('Converts line breaks into HTML (i.e. <br> and <p>) tags.'),
    'process callback' => '_filter_autop',
    'tips callback' => '_filter_autop_tips'
  );
  $filters['filter_url'] = array(
    'name' => t('Convert URLs into links'),
    'description' => t('Turns web and e-mail addresses into clickable links.'),
    'process callback' => '_filter_url',
    'settings callback' => '_filter_url_settings',
    'tips callback' => '_filter_url_tips'
  );
  $filters['filter_htmlcorrector'] = array(
    'name' =>  t('Correct broken HTML'),
    'description' => t('Corrects faulty and chopped off HTML in postings.'),
    'process callback' => '_filter_htmlcorrector',
  );
  $filters['filter_html_escape'] = array(
    'name' => t('Escape all HTML'),
    'description' => t('Escapes all HTML tags, so they will be visible instead of being effective.'),
    'process callback' => '_filter_html_escape',
    'tips callback' => '_filter_html_escape_tips'
  );
  return $filters;
}

Postponed as it is dependent of #546336: hook_filter_info(): Remove $op from hook_filter()

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dropcube’s picture

Status: Postponed » Active
catch’s picture

subscribing.

dropcube’s picture

Status: Active » Needs review
FileSize
16.77 KB

The patch removes hardcoded numeric deltas and uses a literal filter ID, prefixed with the module name of the module that provided the filter.

Status: Needs review » Needs work

The last submitted patch failed testing.

dropcube’s picture

Status: Needs work » Needs review
dropcube’s picture

Updated patch.

moshe weitzman’s picture

Wow, this is great. Numeric IDs are a real big problem when sharing Views or Features or anything like that. Hope this gets some testers. Subscribe.

Dries’s picture

- People expect ids to be numeric. For string ids, we usually use 'name'. Shall we rename 'filter_id' to 'name'?

- + 'fmd' => array('format', 'module', 'filter_id'), -- the 'd' in fmd stood for delta, so maybe that needs to be renamed too.

- No update function yet?

dropcube’s picture

Updated patch.

- 'filter_id' is now 'name', the name of the filters provided by modules.
- the 'name'key in the filter definition, is now 'title', the human readable title of the filter.
- added update function.

Status: Needs review » Needs work

The last submitted patch failed testing.

dropcube’s picture

wrong patch, here is the correct one.

dropcube’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

dropcube’s picture

Status: Needs work » Needs review
FileSize
19.41 KB

Updated fixing tests failures.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

I read through again and this looks sane still.

Is there a patch to move *formats* from numeric IDs to strings? Thats important too.

catch’s picture

Status: Reviewed & tested by the community » Needs review

The core update path only deals with core filters, will contrib modules have to do the same upgrade path themselves operating on filter.module tables?

dropcube’s picture

The core update path only deals with core filters, will contrib modules have to do the same upgrade path themselves operating on filter.module tables?

For now, yes. Each module should know by itself which are it's renamed deltas. See http://api.drupal.org/api/function/system_update_7004/7

catch’s picture

Status: Needs review » Reviewed & tested by the community

Ok that makes sense and I couldn't see a way around it, but worth checking. We should make doubly sure to mention this in the upgrade docs (and for blocks too).

Dries’s picture

Status: Reviewed & tested by the community » Fixed

I've reviewed this patch several times, and it still looks good. Committed.

dropcube’s picture

Priority: Critical » Normal
Status: Fixed » Needs work
Issue tags: +Needs documentation

We should mention this in the upgrade docs, and explain how modules implementing hook_filter_info() should upgrade.

dropcube’s picture

Issue tags: +FilterSystemRevamp
yrocq’s picture

Status: Needs work » Fixed
Issue tags: -Needs documentation

Changes are already documented here : http://drupal.org/update/modules/6/7#hook_filter_info .

#d7csmtl

Status: Fixed » Closed (fixed)
Issue tags: -FilterSystemRevamp

Automatically closed -- issue fixed for 2 weeks with no activity.