One of the most widely installed and utilized contributed modules in the Drupalverse (that is, the Drupal universe) is a module called Views. The Views module is also, in essence, a query builder, but it operates in a far larger context than Webform Report. Webform Report is a query builder within the context of a particular Webform's submissions. Views is a query builder that can work within or above the context of almost anything on our website.
The most common use of Views is to dig into various areas of our Drupal database, pull out the required content data, manipulate and filter the data, and finally present it in some way on our site, for example in the form of a listing on a page or a block. Apart from an impressive set of functionality via the user interface, Views also offers a powerful API for developer use.
Due to the technicalities around the way Webform stores submitted data (as discussed in Chapter 3, Working with Submissions), Webform submitted data has historically not been an accessible area for the Views module. To the relief of many fans of Views and Webform, that has recently begun to change. At the time of writing, the integration dealing with submitted Webform data is not fully matured for general production use (although there are several sites employing it), so we will look at an example of what is available in the current Webform release.
We are going to create a view that will list the names of all published Webforms on our site, along with the number of submissions that have been made to each Webform. This is useful when we wish to have an overview of our currently active Webforms.
For its complex under-the-hood functionality, the Views module is dependent on the presence of the Chaos tool suite (ctools), so we will need to first install and enable that.
Let's navigate to the Chaos tool suite (ctools) homepage at http://drupal.org/project/ctools and download the latest 7.x version. The compressed folder needs to be extracted in sites/all/modules
so that we have sites/all/modules/ctools
.
Now we navigate to our site's Modules page to enable Chaos Tools by checking the box next to its name and clicking on Save configuration.
Having resolved the dependency issue, we can navigate to the Views module homepage at http://drupal.org/project/views and download the latest 7.x version. The compressed folder needs to be extracted in sites/all/modules
so that we have sites/all/modules/views
. Now we navigate to our site's Modules page to enable Views by checking the box next to its name and clicking on Save configuration.
To complete the installation we also need to enable the Views UI (that is, Views User Interface) module on the Modules page (there is no separate download required for Views UI, it is a submodule of Views and is therefore already downloaded) and click on Save configuration.
Submission counter
for View name.The view that we have set up provides us with a table containing all active Webforms on our site. Along with the names of the forms, we also see the number of submissions that have been made to each form. The active form names are rendered as links that will take us to the respective Webforms when clicked.
The listing is sortable by clicking the column headings. When we have more than ten active forms on our site, the view will also contain a pager (that is, links for next and previous pages) to assist with navigating through the list.
In a nutshell, we have defined a database query through the Views user interface. When the view was created we stipulated that the data driving the view would come from the Webform submissions table in the Drupal database. We requested that the view return values of the content title and the number of unique (distinct) submissions against each title, but only for Webforms currently in a published state.
We have barely scratched the surface of what can be achieved with Views. A full and detailed coverage of the module and its various configurable options would fill enough books to cause even the sturdiest bookshelf to break into a sweat. However, we have covered the basics of how this query builder works and had a small taste of how displays may be customized.
In the near future we shall be able to use the Views module to construct customized submitted data reports similar to what is achievable with Webform Report, so that the value of Views is not limited to only non-Webform content on our websites.
The developers of Views have gone above and beyond the call of duty to thoroughly document the module. We may install the Advanced help module (http://drupal.org/project/advanced_help) to access the documentation from the menu toolbar of our sites for easy reference while we experiment with the Views options. Of course, we may also refer to the drupal.org
website for additional documentation and the IRC channels for assistance.