Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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:
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;
}
Comment | File | Size | Author |
---|---|---|---|
#20 | hook_filter_info-clenaup-20.patch | 13.23 KB | dropcube |
#18 | drupal.please-filter-this-more.patch | 14.21 KB | sun |
#17 | drupal.please-filter-this.patch | 13.17 KB | sun |
#11 | hook_filter_info-11.patch | 21.57 KB | dropcube |
#7 | hook_filter_info-7.patch | 12.97 KB | dropcube |
Comments
Comment #2
dropcube CreditAttribution: dropcube commentedFixed tests that failed. Oh, seems to be a lot of confusion in filter.test, the term filter and format are being used indistinctly.
Comment #3
Dries CreditAttribution: Dries commentedCould you provide a motivation for this patch? That helps us put it in context as well as understand why this is 'critical'. Thanks dropcube. :)
Comment #4
dropcube CreditAttribution: dropcube commentedDries, 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
switch
for$op
and$delta
results is hard to maintain and debug.Also see #546350: Remove hardcoded numeric deltas from hook_filter_info().
Comment #5
catchsubscribing. Looks good on a first pass, but don't have time to look in-depth at all now.
Comment #7
dropcube CreditAttribution: dropcube commentedInclude implementation of php_filter_info(), to pass the tests.
Comment #8
Dries CreditAttribution: Dries commentedThis 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.
Comment #9
BerdirLooks nice, however, you need to update hook_filter() in filter.api.php too....
Comment #10
alexanderpas CreditAttribution: alexanderpas commentedsubscribe
Comment #11
dropcube CreditAttribution: dropcube commentedThis 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()
Comment #12
Dries CreditAttribution: Dries commentedLooks 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.
Comment #13
jhodgdonThe 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.
Comment #14
dropcube CreditAttribution: dropcube commentedAdded upgrade instructions: hook_filter() replaced by hook_filter_info(), and removed hook_filter_tips()
Comment #15
webchickAdding the tag back, pending jhodgdon's review.
Comment #16
jhodgdonThis 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.
Comment #17
sunI 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.
Comment #18
sunOf course, I didn't recognize the introduced code in the update function introduced by #546350: Remove hardcoded numeric deltas from hook_filter_info().
Comment #20
dropcube CreditAttribution: dropcube commentedThis patch fixes some coding-style issues and improves/fixes the documentation of hook_filter_info().
Comment #21
sunComment #22
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks.
Comment #23
jhodgdonDoc still needs work here, as per comment #16 above. Assigned to me, I'll take care of it.
Comment #24
jhodgdonTaken care of now.
Comment #26
naught101 CreditAttribution: naught101 commentedRe-opening for a documentation question: What is $op="no cache" replaced with with the new hook_filter_info? Also, a module that I'm trying to upgrade has a
Is that now completely irrelevant?
Also, it would be good to link the "Converting 6.x modules to 7.x" documentation back to this issue, for reference and context.
Comment #27
jhodgdonFrom http://api.drupal.org/api/function/hook_filter_info/7 it looks like the return value has a 'cache' element.
I have just added that to the upgrade guide.
I guess for your default op, you should see if you need to make a prepare/process function?
Comment #28
naught101 CreditAttribution: naught101 commentedThanks, there's already a process function, that was just shorthand. Anyway, I'll see how it goes, the default option probably wasn't previously used anyway...