Question

I want to build a filter for a custom module I built and have integrated with views. In essence, the module allows you to define types of relationships between different nodes. I'd like to create a filter for this so that I can display nodes of a certain type of relationship.

I'm not finding any documentation that describes filters in more detail and explaining the various parts to them. The API documentation is horrific in this regard.

Can anyone suggest a good resource/article on building View Filters in detail?

Was it helpful?

Solution

Have you tried http://views-help.doc.logrus.com/ or the advanced help module?

Edit::
Unfortunately there is no deeper documentation that I know of. I wrote a custom field handler and got most info from other handlers that came with views. I would recommend looking at the views/handlers directory, especially all files beginning with 'views_handlers_filter_'. At least that is what I did.

OTHER TIPS

I think the reason that the documentation isn't as deep as you like is that once you get to the level of creating a filter, the onus is on you to understand what that means. The best Views' documentation is the basic filters that already exist. You should look at things like views_handler_filter_string and views_handler_filter_numeric to see how a really basic filter is structured. Most filters inherit from one of these, because most fields ultimately end up needing either string operators or numeric operators.

The second place to look is views/modules/node and check out the node filters. That handles your basic special filters for things like node types. Once you've figured out how the views_handler_filter_in_operator works, that's 99% of filters and you need to very little on your custom filters except use one of those.

The best documentation on Views API is most likely http://drupal-building-blocks.com/. So that might be an option if you can (and want to) afford it.

As EricSchaefer already said, your best bet except of that book is to use an existing filter that is as close as possible to what you want, copy it to your module, rename and start extending it.

A google search for "drupal create custom views filter" listed this as the first result and that had a link to this, both sound like they could be of use to you.

Here are the tutorials I found for creating Views filters:

They are pretty basic and you might still be left wondering about what's what. There's no other choice but to go clicking around Views functions and methods to investigate properties, inheritance, etc. If I find more tutorials I'll keep adding them.

There is a 2011 book, "Drupal's Building Blocks: Quickly Building Web Sites with CCK, Views, and Panels", that is excellent.

Also do a search on the web for: 110112-WebformInViews2.mov. It is an excellent step by step movie in creating a View.

Or, just make a copy of your view and filter out what you don't want.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top