Quick Filters are the links that appear in the right hand column of many Manage screens. These filters provide users with the convenient means of constraining the list on the page by virtually any criteria, unlike the standard mechanism in place for users to filter the list manually using the build in filter mechanism.
Each page is capable of having a unique set of filters defined for it. The value of the list_filters registry property is actually an array of pages, in which each page contains a list of filters associated with it. For example, the following code sample shows three different list filters being defined for the Manage Entries screen, Manage Comments screen and the Manage Tags screen respectively:
sub init_registry {
my $plugin = shift;
$plugin->registry({
'applications' => {
'cms' => {
list_filters => {
entry => {
myfilter1 => sub { my_filter1(@_); }
},
comment => {
myfilter2 => sub { my_filter2(@_); }
},
tag => {
myfilter3 => sub { my_filter3(@_); }
},
},
},
},
});
}
Below is a list of all the screens for which list filters can be registered:
asset- Manage Assets screenentry- Manage Entries and Manage Pages screenping- Manage TrackBacks screencomment- Manage Comments screentemplate- List Templates screentag- Manage Tags screensys_user- Manage Users screen (system wide)user- Manage Users screen (blog specific)
The Anatomy of a List Filter
Listed below is a simple list filter that will be listed on the Manage Entries screen. Following the code sample we will explain each of the registry properties and what they mean.
sub init_registry {
my $plugin = shift;
$plugin->registry({
'applications' => {
'cms' => {
list_filters => {
entry => { #1. the screen the filter will be listed on
my_filter => { #2. the unique identifier for the filter
label => "My Filter", #3. the display name of the filter
order => 100, #4. the sort order of the filter
handler => sub { #5. the filter handler
my ( $terms, $args ) = @_;
$terms->{status} = 2;
},
},
},
},
},
},
});
}
List Filter Properties
label- the display name of the filterorder- the sort order of the filter when other filters are present on the pagehandler- a subroutine which takes as input a hash reference to the list of filter terms, and a hash reference to a list of args used in rendering the current page
List Filter Handler
Each list filter is passed two parameters:
- A hash reference to the list of terms that will comprise the filter against the current object being viewed
- A hash reference of all the arguments used in viewing the contents of the current page
For example, an entry consists of the following properties:
- id
- blog_id
- status
- author_id
- allow_comments
- title
- excerpt
- text
- text_more
- convert_breaks
- topingurls
- pinged_urls
- allow_pings
- keywords
- tangent_cache
- basename
- atom_id
- authored_on
- week_number
- template_id
- category_id
Therefore to compose a filter handler for the entry page, or Manage Entries page, the following code will register a handler that will only show entries with a status of "2" (or Published), and a title of "Foo".
handler => sub {
my ( $terms, $args ) = @_;
$terms->{status} = 2;
$terms->{title} = "Foo";
}
The ways in which a list can be constrained is limited only to the properties of the object being filtered.
1 User Contributed Notes
Above it says "Below is a list of all the screens for which list filters can be registered...". Actually, you can register filters for any object in the system (both those included with MT and those you create).
In your plugin, you register objects using "object_types". So if you register "foo", then you simply attach your filter to "foo", and you've got a new quickfilter. Unfortunately, there isn't a listing screen for that object - so you'll need to build one for yourself.
When you do, make sure that it has the quickfilter widget in the sidebar - it will be populated with any quickfilters automatically, but if the widget isn't there, you won't get any.
There are also objects - such as notifications - that don't include the widget in their listing screen. So if you have defined a list_filter on an object, check to make sure that the quickfilter widget is defined in the listing template.