Using Views Programmatically

Session evaluation:
Evaluate this session
Speaker(s):

Video by Variant Studios

This session will cover progressing beyond simply configuring and using views to creating and modifying views programmatically with both views hooks and views templates.

Despite not being a part of Drupal 6 or 7 core, Views has become a cornerstone to nearly every Drupal site. And while Views provides some wonderful out of the box tools such as exposed filters, paging and sorting, it's often frustrating for developers who are accustomed to creating complex sql queries and other data manipulation to work within the confines of the standard views user interface. This presentation will aim to provide developers the information to break them free of the view ui.

The session will include

  • Creating views in code - allow your modules to create views and a discussion of why you should do this.
  • Modifying views output - we'll discuss views templates and focus on views hooks so you'll know when and where to manipulate data to get the results you need.
  • Query altering - for the hard core SQL folks, we'll discuss how to modify view's SQL queries to perform operations that are difficult or impossible with the standard views UI.

This session has a companion demo module available from: http://drupal.org/sandbox/jyee/1180682

Schedule info

Time slot: 
12 June 10:45 - 11:30
Room: 
Concert Hall

Passing by reference

A post session question was asked about why some arguments are passed by reference (i.e. &$query) and sometimes they are not (i.e. $query). My Initial answer was that I had a typo... but when I went to verify the API entry, it turns out that I was correct.

Drupal 7 uses PHP 5.3 and allows objects to be implicitly passed by reference. Drupal 7 makes use of this for core objects. So, hook_query_alter($query) is actually passing the query object by reference.

Many modules, particularly ones that have been ported from Drupal 6 haven't changed, so that is why Views is still explicitly passing by reference.