Drupal Views Partials: Nested Views

24 February 2015

So if you’re working with complex data sets or some sort of workflow system in Drupal, you’ve likely encountered the difficulties in trying to extract that information using views over multiple nodes using a single unique value. For me, recently, it was a site that uses a lot of webforms to collect information from users (with accounts) that need to be viewed by another type of user. These administrative users would want to view who submitted Webform A, with a link to view the submission, but they want to be able to see more information about the user than the standard “/node/[nid]/webform-results” would give them. A view would be perfect; just collect all of the webform results into a table and add a filter for the Content: Title so you only get Webform A. But then, they would like to know if the user also completed Webform 2, because that form is an important part of the workflow and process that Webform A represents. What do you do?

Don’t you wish you could just rewrite complex sections like this into a rails application so you have more control over stuff like this? Just me? Okay.

Enter View: Include View

This is a free feature you get when you install the Views PDF, which this site has for other workflows and features.

When you are adding fields to a view, you can actually include another view! No, it is not called View-ception. Please, just don’t. When you click ‘Add’ under the fields section, you can select ‘View: Include View’ to include a whole other view into your current view. They are listed by their machine name.

Side note

When I say “whole other view,” I mean that you can’t just pick a different display of the current view to add in. I’ve wanted to do this, but you can’t.

Now, you just have to create another view that shows webform submissions, has the Submitted User relationship, and the UID contextual filter (argument). Add in the filter on content title to get the right webform. When you go to include it in the original view, you can pass the submitter’s UID as an argument to the included view.

Now it just works!

Related Posts