hook_filter_info(): Remove $op from hook_filter()
dropcube - August 11, 2009 - 18:55
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | filter.module |
| Category: | task |
| Priority: | normal |
| Assigned: | jhodgdon |
| Status: | closed |
| Issue tags: | FilterSystemRevamp, Needs Documentation |
Description
Introduce a new hook_filter_info to allow modules to declare input filters they provide. The input filters are declared using an associative array (hook_menu-alike registry structure).
Preparation, processing and configuration are invoked using the callbacks defined instead of calling hook_filter($op, ...).
Example:
<?php
function filter_filter_info() {
$filters[0] = 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...'),
'process callback' => '_filter_html',
'settings callback' => '_filter_html_settings',
'tips callback' => '_filter_html_tips'
);
$filters[1] = 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[2] = 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[3] = array(
'name' => t('Correct broken HTML'),
'description' => t('Corrects faulty and chopped off HTML in postings.'),
'process callback' => '_filter_htmlcorrector',
);
$filters[4] = 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;
}
?>| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| hook_filter_info.patch | 9.02 KB | Idle | Failed: 11962 passes, 2 fails, 0 exceptions | View details | Re-test |

#1
The last submitted patch failed testing.
#2
Fixed tests that failed. Oh, seems to be a lot of confusion in filter.test, the term filter and format are being used indistinctly.
#3
Could you provide a motivation for this patch? That helps us put it in context as well as understand why this is 'critical'. Thanks dropcube. :)
#4
Dries, this issue comes from an old and ambitious one: #258939: Filter system revamp.
Motivations:
- Cleaning up the filter API to make it into an "info" hook, consistently with others info hooks in core (hook_menu, hook_theme, etc..)
- Benefits of registry-style info hooks is that they do NOT get re-called every time, which is a performance win and means less unused code loaded in every page request.
- If decided, filters definitions could be altered: hook_filter_info_alter(), so that this hook behaves like other "info" hooks.
- Code in nested
switchfor$opand$deltaresults is hard to maintain and debug.Also see #546350: Remove hardcoded numeric deltas from hook_filter_info().
#5
subscribing. Looks good on a first pass, but don't have time to look in-depth at all now.
#6
The last submitted patch failed testing.
#7
Include implementation of php_filter_info(), to pass the tests.
#8
This looks like a nice clean-up, and one I support. Filters are used a _lot_ so I wonder if there is any performance regressions due to this patch. I doesn't look like there would be one. I think this is RTBC, really.
#9
Looks nice, however, you need to update hook_filter() in filter.api.php too....
#10
subscribe
#11
This patch updates filter.api.php as pointed by Berdir. However, the documentation can be improved in follow-up issues, as there are other issues pending, for example #546350: Remove hardcoded numeric deltas from hook_filter_info()
#12
Looks great. Committed to CVS HEAD.
Marking this as 'code needs work' because we need to update the upgrade instructions and follow-up on the remaining issues.
#13
The upgrade doc definitely needs some work, see also #548308: Remove hook_filter_tips().
There's currently a section in the update guide that says the parameters for hook_filter() have changed - http://drupal.org/update/modules/6/7#hook_filter_params -- but hook_filter() no longer exists by that name at all, so that section needs to be removed or rewritten.
So it looks to me as though what needs to be documented is:
- hook_filter changed its name to hook_filter_info() (I think? not sure which issue that is)
- new parameter for hook_filter_info()
- No more hook_filter_tips()
Not all of that is related to this issue, but it all needs to be fixed, and possibly there are other things? I'm not sure. If someone could make a coherent list of the changes, that would be a good start.
#14
Added upgrade instructions: hook_filter() replaced by hook_filter_info(), and removed hook_filter_tips()
#15
Adding the tag back, pending jhodgdon's review.
#16
This does still need some work. I will take care of it. In particular, the old upgrade guide section on hook_filter() needs to be removed or updated. Not sure of other problems, as I haven't reviewed in detal yet.
#17
I really should not be doing this...
Great, now let's fix the introduced coding-style issues and improper documentation.
Apparently, this patch is not guilty for all changes, but it seems like the other patch that changed the structure of hook_filter_info() is not tagged with FilterSystemRevamp.
#18
Of course, I didn't recognize the introduced code in the update function introduced by #546350: Remove hardcoded numeric deltas from hook_filter_info().
#19
The last submitted patch failed testing.
#20
This patch fixes some coding-style issues and improves/fixes the documentation of hook_filter_info().
#21
#22
Committed to CVS HEAD. Thanks.
#23
Doc still needs work here, as per comment #16 above. Assigned to me, I'll take care of it.
#24
Taken care of now.
#25
Automatically closed -- issue fixed for 2 weeks with no activity.