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()
Comments
Comment #1
dropcube commentedComment #2
catchsubscribing.
Comment #3
dropcube commentedThe patch removes hardcoded numeric deltas and uses a literal filter ID, prefixed with the module name of the module that provided the filter.
Comment #5
dropcube commentedComment #6
dropcube commentedUpdated patch.
Comment #7
moshe weitzman commentedWow, 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.
Comment #8
dries commented- 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?
Comment #9
dropcube commentedUpdated 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.
Comment #11
dropcube commentedwrong patch, here is the correct one.
Comment #12
dropcube commentedComment #14
dropcube commentedUpdated fixing tests failures.
Comment #15
moshe weitzman commentedI read through again and this looks sane still.
Is there a patch to move *formats* from numeric IDs to strings? Thats important too.
Comment #16
catchThe core update path only deals with core filters, will contrib modules have to do the same upgrade path themselves operating on filter.module tables?
Comment #17
dropcube commentedFor 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
Comment #18
catchOk 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).
Comment #19
dries commentedI've reviewed this patch several times, and it still looks good. Committed.
Comment #20
dropcube commentedWe should mention this in the upgrade docs, and explain how modules implementing
hook_filter_info()should upgrade.Comment #21
dropcube commentedComment #22
yrocq commentedChanges are already documented here : http://drupal.org/update/modules/6/7#hook_filter_info .
#d7csmtl