Artificial Intelligence

Views 3 makes programmers happy

Views 3 addresses some of the most stubborn parts of Views 2, and significantly improves the way Drupal programmers deliver features to clients.

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


Similar posts

Get notified on new marketing insights

Be the first to know about new B2B SaaS Marketing insights to build or refine your marketing function with the tools and knowledge of today’s industry.