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. &lt;br&gt; and &lt;p&gt;) 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;
}
?>

AttachmentSizeStatusTest resultOperations
hook_filter_info.patch9.02 KBIdleFailed: 11962 passes, 2 fails, 0 exceptionsView details | Re-test

#1

System Message - August 11, 2009 - 19:22
Status:needs review» needs work

The last submitted patch failed testing.

#2

dropcube - August 11, 2009 - 19:35
Status:needs work» needs review

Fixed tests that failed. Oh, seems to be a lot of confusion in filter.test, the term filter and format are being used indistinctly.

AttachmentSizeStatusTest resultOperations
hook_filter_info-1.patch11.64 KBIdleFailed: 12083 passes, 2 fails, 0 exceptionsView details | Re-test

#3

Dries - August 11, 2009 - 20:41

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

dropcube - August 11, 2009 - 21:07

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 switch for $op and $delta results is hard to maintain and debug.

Also see #546350: Remove hardcoded numeric deltas from hook_filter_info().

#5

catch - August 11, 2009 - 22:09

subscribing. Looks good on a first pass, but don't have time to look in-depth at all now.

#6

System Message - August 12, 2009 - 08:02
Status:needs review» needs work

The last submitted patch failed testing.

#7

dropcube - August 12, 2009 - 23:46
Status:needs work» needs review

Include implementation of php_filter_info(), to pass the tests.

AttachmentSizeStatusTest resultOperations
hook_filter_info-7.patch12.97 KBIdleFailed: Failed to apply patch.View details | Re-test

#8

Dries - August 13, 2009 - 11:46
Status:needs review» reviewed & tested by the community

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

Berdir - August 13, 2009 - 12:10
Status:reviewed & tested by the community» needs work

Looks nice, however, you need to update hook_filter() in filter.api.php too....

#10

alexanderpas - August 13, 2009 - 13:35

subscribe

#11

dropcube - August 13, 2009 - 14:24
Status:needs work» needs review

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()

AttachmentSizeStatusTest resultOperations
hook_filter_info-11.patch21.57 KBIdleFailed: Failed to apply patch.View details | Re-test

#12

Dries - August 13, 2009 - 19:54
Priority:critical» normal
Status:needs review» needs work

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

jhodgdon - August 14, 2009 - 17:15
Issue tags:+Needs Documentation

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

dropcube - August 21, 2009 - 05:22

#15

webchick - August 21, 2009 - 08:08
Issue tags:+Needs Documentation

Adding the tag back, pending jhodgdon's review.

#16

jhodgdon - August 21, 2009 - 16:17
Assigned to:dropcube» jhodgdon

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

sun - August 24, 2009 - 05:46
Status:needs work» reviewed & tested by the community

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.

AttachmentSizeStatusTest resultOperations
drupal.please-filter-this.patch13.17 KBIdleFailed: Failed to apply patch.View details | Re-test

#18

sun - August 24, 2009 - 05:58

Of course, I didn't recognize the introduced code in the update function introduced by #546350: Remove hardcoded numeric deltas from hook_filter_info().

AttachmentSizeStatusTest resultOperations
drupal.please-filter-this-more.patch14.21 KBIdleFailed: Invalid PHP syntax in modules/filter/filter.install.View details | Re-test

#19

System Message - August 24, 2009 - 06:40
Status:reviewed & tested by the community» needs work

The last submitted patch failed testing.

#20

dropcube - August 25, 2009 - 21:28
Status:needs work» needs review

This patch fixes some coding-style issues and improves/fixes the documentation of hook_filter_info().

AttachmentSizeStatusTest resultOperations
hook_filter_info-clenaup-20.patch13.23 KBIdlePassed: 12209 passes, 0 fails, 0 exceptionsView details | Re-test

#21

sun - August 26, 2009 - 05:32
Status:needs review» reviewed & tested by the community

#22

Dries - August 26, 2009 - 10:17
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks.

#23

jhodgdon - August 26, 2009 - 16:52
Status:fixed» needs work

Doc still needs work here, as per comment #16 above. Assigned to me, I'll take care of it.

#24

jhodgdon - August 26, 2009 - 17:21
Status:needs work» fixed

Taken care of now.

#25

System Message - September 9, 2009 - 17:30
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.