cool tech graphics

Views 3 makes programmers happy

Filed under:

There are five programming customizations that I've had to do over and over with Views 2:

  1. Create custom exposed form filters, via hook_form_alter() and/or hook_views_handlers()
  2. Create "Sort By" exposed form fields.
  3. Create aggregates by adding GROUP BY via hook_views_query_alter() or hook_views_pre_execute()
  4. Create WHERE clauses what support OR via hook_views_query_alter() or hook_views_pre_execute()
  5. Hack up the pager to match client comps

All of these are addressed by Views 3:

Exposed form is now a plugin

I was very happy to see: class views_plugin_exposed_form extends views_plugin.

The new class for exposed forms can now be extended to provide custom functionality; however, Views 3 exposed forms are so feature rich, I may not ever find the need. One huge benefit is the array of options that are available: Submit buttons, reset button (awesome!), and sort buttons. Even though I will likely still use hook_form_alter(), I love having the option to build more robust exposed filter forms for clients.

Views 3 exposed form

Exposed sorts

If you look at the sort handlers, you'll see a new method: can_expose(). With this slice of apple pie, the query() class will ORDER BY using exposed sorts! I've spend countless hours forcing Views 2 to provide this feature, and I am very happy to see this in Views 3.

Views 3 exposed sort

GROUP BY support

The new query plugin takes advantage of the GROUP BY methods in the Drupal 7 database abstraction layer. No more query_alters to get GROUP BY support! Note that I said query plugin: The views query itself is now a plugin and can be extended! I expect to see several contributed modules scoring big wins by extending this plugin.

Views 3 GROUP BY

AND/OR support in the WHERE clause

Just like above, the Drupal 7 database abstraction layer is insanely powerful, and Views just climbs right on board. The new WHERE Groups functionality enables endless possibilities of AND/OR WHERE clauses.

Views 3 AND/OR

Pager is now a plugin

I've suffered many hours in overrides of theme('views_mini_pager') and theme('pager'). I'm glad to say these days are behind me. Not only is the Views 3 pager so feature rich that I'll likely never need to write code, it is now a plugin that can be easily extended. One of my favorite features is the exposed "All items" option, which is something I've hacked into Views 2 theme overrides no less than a dozen times.

Views 3 Pager


Date posted: March 25, 2011


Yes, this is great indeed. I especially love the "Expose items per page" option.

You missed the probably best feature: query is now a plugin so you can use apachesolr/whatever to integrate directly with views.

Thanks for the write up! Wait for the release version of Views3 seems to be never ending. Can you please give me some idea as to how to expose sorts in Views2? Thanks in advance!

It's just not possible without any kind of dirty hack.

If you need this software feel free to test views 3.x. Quite some people already used it, so there are probably much less bugs as in 6.12, which is one year behind views 2.x-dev.

Views 3 looks promising. Thanks.

Excellent stuff - I'm just getting into Drupal right now, and I'm really loving all the stuff available just on a stock install - but this is totally great!

I can just imagine. It is a very popular module for Drupal and them upgrading it with some significant changes is good news to all views 3 users. Although I did read about it have dependency on Chaos tools which can be seen as both good and bad, but overall it is still a great release.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <cpp>, <java>, <php>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Metal Toad is an Advanced AWS Consulting Partner. Learn more about our AWS Managed Services

About the Author

Tony Rost, Chief Technology Officer

Tony believes that customers' technology problems can be solved with deep respect, sound data, strong process, and adventurous teams. He uses data-driven methods to improve all stages of the development lifecycle – from design, to beta, to final deployment. With numerous ties to the open-source community, Tony also works to solve client problems faster and more effectively with well-tested open-source solutions.

Several dozen products have shipped under his guidance over the past 14 years: collaborative internal sites at Nike, social networking integrations with Adidas, server-monitoring websites at Hewlett Packard, open source contributions to Drupal, entertainment sites such as The Emmys, community sites such as FearNET, and HTML5 apps for tablets and Smart TVs.

Have questions?