Views Mini-Course, Part II: Creating Flexible Views with Drupal 7 [May 8, 2013]
Views Mini-Course, Part II: Creating Flexible Views with Drupal 7 [May 8, 2013]
Want to learn more about Acquia’s products, services, and happenings in the Drupal Community? Visit our site: http://bit.ly/yLaHO5.
In part two of our mini-course on views, Heather James, training manager at Acquia will show you how to create flexible lists of content with Views. Views comes with a number of pre-built Views which you can customize. This webinar will cover how to override how content is output.
You will learn about:
• Expanding fields available with relationships
• Dynamic lists with exposed filters and contextual filters
• Using Flags as a relationship
• Using Entity reference as a relationship
• Where you can go to learn more about Views
Hannah Corey: Today’s webinar is Views Mini - Course Part II: Creating Flexible Views with Drupal 7 with our manager of training, Heather James. We’re really excited to have her doing the series with us. I’m Hannah Corey. I’m a marketing specialist here.
Heather James: So this is me. I'm Heather James, as Hannah was saying, manager of training the program at Acquia. Our training program, you can see the events there up on the website, we have them all over the world. I actually counted 80 events just in the U.S. upcoming in the next couple of months. Our course materials are actually maintained in-house and we’re continuously updating them. It lets us keep on top of the latest developments and make sure it’s fresh as well. Our trainers are actually our partners. So these are folks who are experienced developers. I have to say - I love to say, they actually like getting away from behind the computer and helping people. They’re the kind of people that others in their company go to for help. So as subject matter experts, they’re really good. We can also provide tailored packages as well for your teams. So please contact me if you have questions.
So we’re in the second part of the Views Mini Course: How to Build Flexible Views. Next week is the last part of this course. These three parts are just an introduction. Views is such a powerful module. I could go on forever on Views probably. After that we’re going to follow up with one class, just on how to configure accounts in Drupal. Something quite simple but people often get a lot wrong with it. Then we’re going to have a four-part mini course for product managers. So I'm very excited about the folks - my colleagues who are going to be helping out on that course this summer.
So what we’re going to do today is look at how to build flexible views. We’re going to see relationships, attachments, contextual filters. So probably things you may have heard of before and hopefully some things you haven’t considered yet. So if you’re watching this webinar, you need to know a bit Drupal already such as how to add content, customizing content types, installing and configuring modules. So we’re sort of picking up from last week as well. So I’ve already explained how Views work and how to add a new View and just manage displays.
So just to recap what we covered, if you go to j.mp/acquiaviews1, I've got all the notes from last week’s class up there. You’ll be able to follow along with what we did. There’s also the recording as well. So what we covered last week were the main concepts of the workflow. If you need to think about Views, think of it in two parts: first what you’re selecting and then how it should appear. So we talked a bit about selecting a base table and then applying various filters and then choosing formats and displays. So just keep that workflow in mind. You’re choosing what you’re querying, you’re limiting your selection and then selecting formatting and displays. As long as you understand at this stage that Views is a query builder, then we’re set to go and we can continue on and dig deeply into the Views UI.
So one thing I said about the Views UI last week was that the Views wizard disappears. So I’m really not going to focus on the Views wizard. Just think of it as a way to get your quickest settings completed but quickly you’ll be moving into the advanced Views editor. So we’ll spend a lot of our time there. This is how we sort of broke this up last week into these two mains section, what to filter and how to format and display. So we’re going to look at, for example, field formatting, filter criteria and how you can actually expose filters, sorting and how you use sorting, for example, in tables, and we’re going to look at contextual filters, number four, and relationships, number five.
We’re also going to look at - I did touch already on attachments last week because I had a little bit of extra time. So I will touch on that briefly. We’re going to focus a lot on number two, formatting. Then in three and four we’re going to look at the page settings and how you get access control, and number five as highlighted there, the pager, and number six, exposed forms. We’re probably not going to use those much in the session but just to call your attention to it.
So let’s look at formatting and display. There are a number of formats available. You’ve already seen me use, for example, the HTML list last week or the unformatted list as well. There’s also something called a jump menu. So in this example, on my site, I got - showing here in this block a level jump menu. You might have beginner, intermediate and advanced. So that’s one example of how you could use the jump menu with the taxonomy terms.
There’s also table formatting. So table formatting lets you actually put each individual field as a row in your table. When you’re doing your table formatting, just as a tip, make sure you customizing labels and making those columns sortable. People generally expect with dates that they descend in order from most recent on top down. So just try and use these sorts of standardized controls. I’m going to give you a demo but I just want to say as a note, if you’re going to add, for example, a new table, think about how your users are already accessing the table base data. So, for example, we have the title, then the date, then the operations, for example. So if I’m going to add another admin view, I should follow that same order. Overall, just with anything you add in Views, just be consistent across your site. If you also find with Views that you’re doing a lot of custom formatting such as rewriting output fields or, in this case, you can see it’s quite small in the screen, how to do a custom date format. You might use this little J, big N, little Y to change how your short date show up, if you’re familiar with that PHP formatting. If you find yourself doing this kind of thing a lot using this custom date format, then change it across the whole site. Go into your date and time settings and change the format or add a custom format for your short date and change the short dates all across your site. So you really want to think about that reusability. So instead of going and trying to do it custom every time, use the short format that you’ve customized just all across the site. In general, we’ll kind of keep that in mind as I do the demos today. Just try to think of reusability all across your - as you’re developing, I should say.
As well, use the default view mode. So if you find yourself doing a lot of field configuration and display configuration within Views, you might be interested in trying display suite to create these custom view modes. I had decided not to go into display suite today because I think it might make a good class on it is own and there are some great materials out there for display suite but just so you can know. The view modes - we talked a bit about this last week. Here’s a teaser and the full content for some website here. Try to use the display suite view modes instead of always of doing fields formatting and views. I guess this just goes to the point, try and reuse the image styles across multiple different areas on your site. It's going to make everything so much easier. So just as a principle with Views, be consistent, think of reusability, think of who can access it, who’s actually going to use the content, and how they need to access it.
So speaking of access, I wanted to just first mention that we should consider, when we’re creating Views, who’s actually going to get access to the content. We’ll actually be looking at this in more detail in my first demo. I should call your attention to the fact that if you’re going to set by access, it’s most easy to do it by specific permission rather than a role. You may be tempted to say, “Oh, give all administrators the access to this” or “all editors access to this.” You may find in the future, you’ll add another role who has some more permission. So do it by, for example, permission, in this case, whoever can access the content overview page for example.
So the next point is filters. So filters actually - mainly what we’re doing with filters is limiting the selection across the whole site. I’m giving you an example here of an exposed filter because I think you saw filters last week. What I didn’t show you was actually sharing it across the site - I’m sorry - sharing the access to the filter with peer users, that’s what I mean to say. So in this screenshot you can see that someone can type in an author name and apply it and see just the list of that author’s content. So I’m going to do a demo just to show you that. We’re going to edit an existing view I’ve created and we’re going to expose the filter to viewers and even insert an edit link for administrators and change the path and the access control as well. So I’m just going to go to my site here. So I’ll go to my structure Views list here and I’m going to go to content by user. So here’s a view I made earlier.
First I’m going to show you what it looks like from here. I’ll show you what I setup first. So I made a list of content. Not a user list but actually a content list. So we have the fields, titles and post date and it's formatted as a table. So I’ll show you what that looks like. So this is just showing me all the content across the site. What I can see is if I pick a specific author and start typing their username and click apply, then I can just see all that content by the author. The reason I made this is because when I go to my normal content list, one thing I find frustrating is that there’s no way for me to browse the content by author and can’t even sort on this author field. So as a content editor or site editor I find this really difficult. So what I’ve created is another view, and you can see how it’s showing up here in my administration interface. It’s actually showing up as a tab on my content menu here. I made it so I can browse. So what I’m going to do to this is add an edit link here. We’ll develop that throughout the class today.
So let me show you, first of all, how we expose that filter. So the filter we added was the author ID and I could have specified a specific author. I’m just going to deselect that there. I could say, for example, just show me content by a specific author, site admin, for example. Instead, if I expose it that let's anyone who’s looking at it to choose their author. So do author name and I can say type the author’s user ID, username. So here we go. So let’s see how that looks now. So you can start to see how it gets much more helpful. I’m going to add another field here which is going to be an edit link. So we often think of all the different ways that you use Views on your site but the administrative views are really helpful. So there we have the edit link. Cool. So it’s getting somewhere now. I’m going to save it and then just refresh this and see what changes we have made. There we have the link showing up. The other thing I probably want to do, as I was talking before about table formatting, is letting people sort. So I’m going to change it so you can sort on the title. So I go into the table settings for that. I can make that field sortable. As I was mentioning before about date sorting, people expect that the default order is descending. So I’m going to make the post date the default and I’m going to make the most recent stuff show first. So I can save that and refresh and see what changes there are. So now the content is sortable by title and by date.
So I'm just going to go back to my presentation briefly and talk a little bit about pagers. I will actually talk to you about the menus to tell you how I got that menu up there but we’re just moving swiftly along. On your Views, you’ll have to decide whether or not you need pagers. Here, I've show you the configuration options. For example, for this block here, on the right where I’ve actually set it to have a mini pager and just show me three items. If you’ve been using a lot of websites now as well, you probably noticed the infinite scroll. I didn’t install that module myself because it gives me vertigo but it’s very popular. It simply means that instead of having a pager at the bottom, it would continue to load the additional - to load the additional list. I'm going to give you a demo of that block just on the site so you can see how that works with the Ajax loading for the sidebars. Then I go back to look at the site here and I can see that news article block in the side. Hopefully you can see that okay. So the Ajax loading means that I can load the next list of content without having to reload the whole page because it’s actually pulled in all the results. So I’m going to edit that view and show you where that setting is. So I'll go down to advanced and look at Views, Ajax, yes. It’s really a simple toggle of yes or no. By doing that, like I said, all the content gets loaded. So what you don’t want to do is use that setting on, say, a view that lists all the content on your site. That would be a lot of content at once. You want to be careful, I suppose. I think it’s pretty useful in the sidebars though, sidebar blocks too.
Now I’ll show you the attachments. We did talk about this briefly last week. I gave the example of listing the news articles on their site and then having just the titles of these, say, older articles. That just allows us to get more content up and probably makes it a little easier to browse. So let’s just look at what we did last week. So here are our news articles on the front page. I have three or two articles showing up and then three articles showing up in the attachment here. So I’m just going to edit the view. Here is the regular list. So that’s just showing us two items. That’s showing an unformatted list. I’m just going to scroll down so you can see. Fantastic. These are kind of - it’s just showing the title, the updated date and image. The attachment - if it loads today - is attached to that display. So when you do your attachment positions, you can actually choose whether it’s before or after, whether it, obviously, inherits different filters you set. Then, finally, you can set it to skip three or I should actually say skip two in my case because I’m only listing two items of content. So that basically lists the upcoming kind of older news, for example. Save it and go down. As soon as it refreshes - we’re getting more news now. At least.
Okay. So then I want to show you relationships. So we spoke about this last week that the first decision you make, especially when you select the Wizard is what your base table is. That’s content - sorry - content or users or taxonomy terms. You can’t change that later but what you can do is get other data from other tables. So say, for example, you’re making a list of users. You would not have access to any content because you wouldn’t - it’s the user table. So what you actually do is make it join on what content was authored by a specific user. Here’s an example where we’re using a module called Entity Reference. Entity Reference actually is on the job listing and there’s a company referenced, there's another type of content node of any selection they want.
So in this example, that becomes a type of relationship you can reference. I think it’s a little confusing until you actually see the demo. So what I’ll do is actually just do a demo and show you what happens when you add a relationship to something. So let’s see. I’m going to go to my structure Views and we’ll say, add a new view, and we’re going to say user list, busy, busy users. So we’re going to show a user list and we have a page automatically created. As you can see, that was my base table, the choice user. I won’t be able to change that later. So we’ll see here, if I want to add some additional fields, let’s say I want to add the user’s name - that’s not showing up for some bizarre reason. I’m just going to cancel this and see why that happened. I’m not sure. So add new view. Add busy users, users and - I actually didn’t check the display format. I really meant to choose fields. So the calendar at the end is available because I have another module that’s installed which I’ll show you later, which is calendar.
So here we have a list of usernames. So cool. It got usernames here. I only want to see the users that have posted content recently, and I want to see what that content is. So, say, a title from a recent post. So if I go to fields here and I look for something like titles - it’s not showing up - or content, nothing, and say, article. Nothing is showing up in terms of anything related to - kind of like nothing related to content will show up because I’m just in the user table. As we can see, the only thing that’s available are user fields. I’m just kind of belaboring the point of it. So what we’re going to do is add relationship. In case we’re adding it by author. There are so many relationships that you could actually add. I think that what you probably want to do is when you add another module such as Flag or Entity, is to see what relationships became available. In this case we’re just going to stick with nodes. So we can see now the user content that’s been authored by a specific user.
Now, when I go to add field, I should see content title. So now that - as you saw before when I tried to get anything related to content it wasn’t available but now it is. So just to move things along a little bit, you can see here I have some users that have no content and some users are actually quite busy. I’m just going to go jump ahead to this one I've made earlier because I just want to speed things up a little bit to save the time. So what we’ve done here is that we’re actually using the latest post as a way to filter. We don’t want to see people who haven’t posted to content. Remember it’s just showing the busy people and we only want to see content of course or recipe type. I don’t really want to - I don’t care if some site administrators have posted a basic page on the site. I want to see those who are contributing new content. So that’s actually used then as a filter to kind of filter out anybody who is not busy. So we can see a specific user and then we can see their actual - whatever content they’ve post. So we can actually - I think I should rearrange those fields so it makes a little more sense. Username, picture, role. Here we go. So you get a username, what their role is and then what their latest post was. It wouldn’t have been possible without their relationship. I've got so many things to show you. Let’s see how much time we have.
Okay. The next thing is contextual filters. I guess this is probably something that is so widely used and I think it’s kind of confusing at first. To be honest, a lot of the configuration is honestly confusing. The terminology doesn’t make a lot of sense. I know they worked really hard on it but we’ll just work through it slowly. So I want to give you an example of our site where we’re looking at a course called cake decorating. This is an all level course. I want to see any recipes that are also related to all levels. So that would be an example of using a contextual filter. Another contextual filter example would be - I’ll show you on the website, our own website. If you look at my user profile, you can see my recent blog post. So what it’s doing there is looking at every single user, basically they’re checking by their user ID. Is there any content by this user ID when we’re looking at this user’s profile? Let’s list it out here. So in the previous class someone was asking “What if you want to have 250 views?” My guess is that if you want to have that many views it’s something you can do programmatically like this using contextual filters. So let’s think of it that way. It’s sort of a way you can get through a lot of content. Let me see.
Okay. I’ll just do a demo really quick. I think I got time. To show you - using a block view, we’re going to pull in a user ID and select, sort and format the content. We’re going to do that user profile. I can also show you the recipes one as well. So I’m going to go back to - look at our user page. Let’s say we look at a particular user here. We don’t see any content by this user just yet. So what we’d like to do is have a list of their titles, anything that they posted to the site. So I’m going to go to structure views. Probably at this stage you have a pretty close idea of what I’m going to do now. You’re now going to go show content. I’m going to show – I’ll type all. I’m quite happy to do that. I don’t need a page, actually, in this case. Probably the first time we’re just seeing - creating a block. We’ll do an HTML list of titles which is good enough for our needs now. So as that is, actually just from having done that, I just want to show you. I'm going to click save because it is quite helpful to see. Just from having done that one thing using the wizard, making a block, a block is now available under structure blocks. User content list here. I can actually place it right under my content. So here is my page content. I'm going to show it on the user content list. So if I go to my user profile I’m going to go by - look at this user again. We’re seeing all the content by all the users on probably all the pages. So we don’t want that, right? We want to limit that block to only show up on user profile pages which in this case - let’s go back to user page. We’ll be under users as a path so we’ll use that.
You can also set that block to show up only on specific content types or for specific rules. In this case, we’ll only list it on pages that start with users. I’m putting in the wild card there. /and * makes the wild card. So we’ll use - those work for anything like a user profile. So I go to refresh here, still seeing it on the test editor page but I am not seeing it on, for example, my homepage. Okay. Cool. So let me go back to that user content list here. I’m going to edit the view from here. So you may have seen this or see me do this before using the contextual link. It's kind of a quick link. What we’ll have now is a chance to just filter out whatever that user’s content is. So we looked at the users/ and then the username, and that’s what is in the URL and that’s what is available to Drupal. So we’re going to look at it - the author ID. As you probably guess, there is no other filter available because this is the content view. This is not a user view so none of the other user information is available. So we’re going to use a user ID from URL. That’s when the filter is not available. When the filter is available we will specify validation criteria. That will be to a user. I have user and we don’t have to do anything. Okay. How to handle it if doesn’t validate. So if there isn’t anything, you can just hide the content or you could have something like a no result found message. I'm going to leave that. Actually, I have a better example of that later. So we will - I’m just going to double check here. Okay. It should be okay. As you see in the preview here, we’re not getting anything actually showing up because we don’t have a user’s ID setup. So if I put any user ID and click update preview, it’s going to check by that user one which happens to be like the site admin. I think there's probably a user two. We’re seeing different content, and user three just to show you. Here we go. So we’re seeing different content by different users. That’s not going to impress you, really, until you actually see it in that user’s page. So after I click save you’ll notice I’m brought back to the view where I was editing it. So here we’re seeing the user - test editor’s content.
Let’s prove it by looking at another user’s content. So we’ll go - which one did she or he not edit? Okay. We did all of this. It's the same user. Here’s the test editor and we can see this user’s content list. So this is taking the user’s ID from the URL and changing what’s available or what’s displayed based on that contextual filter, whatever that context is. One thing - I guess I’ll - I think I have some more things to show you. There’s more fun stuff to show you there. Sorry. You know demos are so fun. I'm just going to show you the related recipes because I think that’s another example that’s helpful. So say, for example, you're looking at a particular course such as introductory baking which is available, I think, I said to all levels for this example here, that's the term. Here's the related recipes by all levels. So I'm just going to edit that view and show you how that works. So this is, again, it is actually just a block view as well. Here we have the - contextual filter is actually the level. So that's the related - you can think of it as the related field between the two pieces of content that I'm relating. So courses and recipes both have levels in them. Here I can show anything that’s related by the specific vocabulary. So there's option there for vocabulary where you can load the default filter from the term page, load it up from the node pages, so that's good for related taxonomy block. That's kind of the key thing you need to do. In my case I limited just by specific vocabulary but you can imagine by selecting multiple vocabularies, you can actually have a much more organic way to relate content all across your site. I also overwrote the title in this case. So when we see the block, you'll see this basically the level name is being pulled in to the block title. So there we go. That is - the last part is defining the validation criteria when a filter is available.
What I thought was useful to do is if there are no results, you can display the content of no results found. If we go back - I haven't shown you this yet but if you go to no results found, you can have, for example, just text message: “There were no related recipes, why not add one?” You can add a link then to your - to prompt someone, if there is no content, at least try and go and add some content. So you can think of ways to encourage content creation instead of saying there's no results here. So this is what would show up if there were no results in there.
Okay. The last thing I'll show - no, there's a few more things I want to show you - is adding a link to your menu. So you can actually create menus with your Views as well, menu tabs. You can also create a link from Views to any of your existing menus. So I think this is something that’s actually quite often overlooked. I wanted to show you how to do this because, especially if you're making administrative Views, you may want to leverage that. So in this case I added the content by user as a menu tab, in fact not just a normal menu entry, as you might do in other examples. I put it into the management menu. The actual path, the page settings, the path, is part of what determines where your menu is going to show up in the future as well. I'll give you another example of that too. What happens in this case for this view is that the tab shows up under the content list. I've also noted here that the permissions is something we talked about before but that is also going to make sure that it shows up in my admin area and only administrators can access this view. So that is the access to the content overview page.
So another - I think I may have shown this to you last week. It's interesting to me because it's something I use all the time, is sort of - this is actually a menu created with Views. So if I go - this is on my website and it's actually built on Drupal 6 but I think it's useful to see because it's just quite handy if they have events in Europe or Canadian events. So I will go to edit this view and show you how that works. So as our menu tab here, for example, the tab is Canada, it's a menu tab and I have set the weight, for example. I've done the same thing for Europe. I've added a menu tab. Still loading] options for Canada. It's the same thing for Europe, added a menu tab and put in the link there. What they're doing, actually, in the view is showing up as links between each other, between each of the displays. The defaults - I'm sorry. The default tab here is set as the U.S. - I'm sorry. The U.S. - the default tab is actually set by the top level menu item or - sorry - the top level of the path. So that's events/ and every other one of them is showing up the child items basically, if that makes sense. I hope that shows maybe a bit - if I go back and look at the view it might make a little more sense. So these individual displays are actually just links between each other in the menu tabs, using menu tabs.
Okay. So I will show you this to demo how to add a menu to your – how to link to one of your menus. I'll also show you how this one works, the content by user one works. So back to our - right here. If I go to the content list - I'll show you, I've already set this up but I'll just go and click edit view from here. You can see the menu option is set as a menu tab within the management menu. So it's going to look for who the parents are in this case. I could have also done a normal menu entry, in which case it won't show up as a tab. I'll give you an example of a normal menu entry now. I'm going to go to structure, views, and I'll give you a recipes. We have a lot of my recipes here, and I'll add this. What I'll do is add it into the menu. I'll show you where I want it to show up, actually, first. That's probably useful. Go back to home. So I got this top of the menu here about all courses, home. So this is my main menu. So what I was going to do is in my menu settings, do a normal menu entry, my recipes, and set it to be in the main menu. I can have it be heavier or lower. Negative numbers are going to bounce up. So I'll put this as a heavier number. So let's see how that works. Save that and go back to my front page. You'll see the menu showing up there. Like I said, you could actually place that link anywhere on your site. On my own training site, I don’t know if I still have it up - never mind - I use that to put in administrative links as well. So there you go. That is just briefly how you can add in menus. You can create as many menus as you like.
Okay. So there are actually so many modules that really love Views and work very well with Views. There's a lot that actually give you templates, calendar is one of these modules. It actually creates kind of quick and easy templates. I'm just going to give you a sense of how that works really quickly. So it used to be - if you're familiar with calendar from Drupal 6, it used to be that it would create kind of a format or field formatter but now it's not. So I'm going to show you. Under structure views, you see here we have add new view, we also have from templates. So this is sort of new with Views 3 if you're new to it. Here we can see, for example, calendar templates as an option. So I can actually create a calendar view of specific fields. Here's field date or last comment or - we’ll just show created field in the - or field date in the node base table I guess would be an example. I think this field date is actually a good example because it's related to my courses and it's not related to my content, just my regular content updated dates. So here we see in the calendar and here we can see an upcoming course. Well, there's one upcoming course anyway. That's basically what calendar does. It creates these kind of quick and easy to make Views templates. It does allow you to do quite a bit customization. I think the great thing is that it comes with all the CSF, formatting just works and it's really a quick way. You could use this to browse content on your site. You could also use it to, obviously, show events listings like that. There are a lot of different displays, week, day, et cetera, that are available. So I'm just going to publish this. [Or save it I should say, and I'm going to click to view week. You can see that similar to the menus I showed you in my Drupal 6 site, you can see how this multiple displays are showing up as menu tabs. So that's quite helpful. Okay. So that's the calendar module.
There's a lot of different ones actually that use jQuery, for example. There's probably as many modules almost as there are jQuery plug-ins, it seems I think, of these types of plug in. The most popular one that I'm aware of I think is slideshow. This is a really handy tool. It's actually giving you another format. So I showed you the jump menu or the table. Slideshow becomes one of the options you have. So you can select how quickly it goes. You can select even the image type. You can even have - text can be in the slideshow. It doesn’t necessarily have to be in pictures, I suppose.
I wanted to talk quickly about the various modules that assist administrators. This is something that is often forgotten when site building with Drupal. It's so worrying because when you see the regular content list in Drupal, it's just - there’s so little you can do with it and it's hard to configure. I even get frustrated just not being able to see my own content so I almost insist on every site that there's some way you can see your own content. So here we see the example of Views bulk operations. I'm actually going to do a demo for you. I want to show you quickly Workbench is another one of these modules, similar to calendar which is actually built with Views. So Workbench is actually a set of views. They just work out of the box. It gives you a list of your own content. It gives you quick access to probably everything that you want to see when you are a content editor, what you've edited, what you've added and quick links to edit content. So it almost seems to me a given. If you're going to build a Drupal site, you'd probably want to put Workbench on it. It's such a handy tool.
If you want to take it a step further, Views bulk operations is super helpful. I feel like I use it all the time. I've got - I had a user put in 20 different items of content, and there was error in every single one but I was able to use Views bulk operations and actually change the value of a specific field, very quickly. So it definitely saves a lot of time. So what I'm going to show you - I'm just going to give you quick introduction to it first, is that Views bulk operations is a field once you've enabled the module. It's creates a field type. Then what you do is you change what operations are available in that field. So I'm just going to show you how to do that. We’re going to go back to my content list by users. I'm going to go to content. You can see my content by user there, and edit my view. So I'll just tell you what we’re going to do. We’re going to add an operations link similar to what we see on our content list here. We’re going to have a selection link which is our Views bulk operations field. Then we’re going to have some options to allow some changing of the content, so some kind of managing tools. So we’ll go to fields - I guess it's sort of belaboring the point to say that I've been enable - installed and enabled the Views bulk operations module and all the dependencies as well. So this is the bulk operations field you're looking for. So I will apply it.
I'm going to change - or selected bulk operations. You can see, for example, unpublishing content might be something you want to do and saving content or maybe removing content from the front page, publishing content, promoting something to the front page. You can see how just being able to do these simple operations can be very time saving. Changing the author is something you might often do. That's quite helpful. So we’ll just slide up and see how see how it goes. Here we get the operations link that's showing up on the side. Remember what I said before about being consistent. People will expect the operations list or check boxes are on the left. So always think about that when you're adding in new fields. So move that over to the left, apply it, and here I've got my select button there, and here are my operations available to me.
Now, you're probably thinking, “Why aren't all administration pages overtaken completely by Views?” Well, in fact, that's what that module admin Views does. So you'd be able to say - it actually overwrites all of administration lists. So definitely check out admin views as an alternative. Here we go. We’re going to see - I can actually see - I can't see the specific author I've selected. I guess if I'm looking at something by site admin, I'm probably clear that this is site admin content but I might actually want to add in the field. I've just realized that might make a little more sense. I'm going to add a field to show the author or the author username. So similar to that problem we had before, author names showing - oh, author ID, ha-ha. I'm not getting the author name because the author name is not available for me. Can you guess probably what I need to do to get that? You're probably thinking “Hmm. How am I going to get the author name here?” You probably guessed I need to add a contextual filter and I'll need to do that on the author ID. So this is just proving the point that if user information was not available - that's not a contextual filter. Excuse me. You want to add a relationship. I hope nobody is taking notes. I'm sorry about that folks. You probably realized what I was doing wrong. So the content author is what we’re looking for. So that's relationship we’re trying to create here.
So now when I go to add a field - someone is laughing at me. I can see the smile. That's great. You caught that, didn’t you? So now we can see the author username is available. So the username is now available instead of just the author ID. So that's far better than what we had before. It's a little more user friendly. So fine that it's there, I think I definitely want to move it over just to finish this off, I guess. I'm going to remove this and move this up and apply to all displays. So there you go. So now you could see - all right. I want to select by just text editor and maybe change the author of a specific piece of content. Okay. So that was good. You got another bonus example of seeing relationships which is great.
So we've got just a few minutes left but I want to go through very quickly, the things we’ll be doing next. So last week, if you watched this class or the last class, you made a view, right? This week as your assignment, please try to add a display that has an attachment with it and maybe use the contextual filter or user relationship to get other data, and add a link to somewhere on your site. If any of the stuff that you've seen today is confusing, I have actually made a tutorial that's in four parts. They're about five minutes each but it goes through contextual filters and using attachments. It's literally 20 minutes long, step by step, very clear. So not as much detail about some of the best practices we talked about today, but there's also a webinar that was just last week with our partners, Suzanne Kennedy from Evolving Web. They have a course, actually, at DrupalCon on Mastering Views Configuration. If you can imagine what we covered and I was able to squeeze in to an hour, if you do a full day long class, you'll get a lot more out of Views. So there's also - this is all in the - the slides we will be uploading as well. You'll be able to get these links easily.
So next week, I'm going to show you how to build your first module with a backup Views. I timed in. In fact, it wasn’t even an hour long. I had to come up with other fun stuff to do next week. Do sign up as well for the following class about configuring accounts in Drupal. It doesn’t like fun but it is interesting and it is really important. We’re going to talk about profile fields and user accounts and roles, a lot of different aspects of accounts on Drupal. Then after that, I think you'd be interested - you might be interested or maybe one of your colleagues is on the project for - Drupal for project managers course.
So next week’s topic, we’re going to do a Views QA. We’re going to go through some views and look at - try and improve the quality of them by going through a checklist. We’re going to talk about theming Views as well. So I want to show and break apart the basic steps of how you go about theming Views. Then we’re going to talk a bit - we did last week and touch on it but formatting and how you configure your formatting. We’re going to do the final steps for caching and performance to improve how your Views actually cache content and load very quickly. Then we’ll build a module to back up your Views. So if you’ve never done anything to back up your Views before, you’ll be really excited to see this. If you’ve never build a module it is super simple and you’ll be very happy you’ve done it. So there’s a lot of events in person as well so please do check them out.
Are there any questions? I haven’t been able to see. There's about a few minutes left.
Hannah Corey: Yes. We had a couple of question come in. The first question is about column sorting. If there is paging, will the sort consider a current page only or the whole set?
Heather James: It will - the sorting will be set across any pages, any subsequent pages. So if you sort it by alphabetically and it like A to J, it will do K through Z on the rest of the site - sorry. K to Z on the rest of the page.
Hannah Corey: Awesome. We have another question on sorting. Will it issue a new query to the database or store at the presentation tier level?
Heather James: I think that - that’s actually a good question. I don’t know the answer to that. I think if you sorted it - I actually don’t know the answer to that question. That’s a good question. I will find out for you next week.
Hannah Corey: Awesome. The next question is can we get a quick look at the generated SQL for relationships?
Heather James: Yes. Okay. Well, if you are a database programmer, you probably have already kind of you’re scratching your head and you’re wondering “What is that?” It's a join. So here we have the join, we’re seeing - it’s very small and very pale. So this is exactly what you would have done if you were writing your query. Is that kind of what you expected to see? I assume so. I guess I won’t get the answer right now.
Hannah Corey: Yes. That’s exactly what they wanted to see. Thank you.
Heather James: Yes. If you’re following along and you’re working on your Views and you can’t see your query settings, remember you can go to Views, settings and you can actually show the SQL query in the live preview. We can talk a little bit about some of those performance things next week too.
Hannah Corey: Awesome. Okay. We have a couple more questions. How can we assess how efficient those joins required by relationship are?
Heather James: I think that’s when looking at the performance statistics will come in. I think once - tune in next week. You’ll see how you can actually export your Views to code. Once you’ve done that, you’ll be able to tweak any of those queries yourself and improve them. You can sort of, in a way, could say let Views be something that you and your team prototype with, and then you may use it sort of as jumping off point to maintain more optimized Views queries.
Hannah Corey: Great. The next question is can you please give us a sense of what kind of things we should not try to do with Views?
Heather James: Yes. I actually - I was going to talk about that with this view of all content here I made. I think that Views - I’m pretty sure this has been hammered through very clearly but seeing this earliest version of Views, the default setting was to show all content and actually - instead of showing fields - I’m just going to edit this one here. Instead of showing fields, it actually would show the full node. So, for example, here, like the full content. So what that meant was if you had a view such as this which shows all content and also uses Ajax, you’re basically trying to pull all the content from your entire site in all at once. So this is sort of - this was basically always the fear of - for example, when we did Drupal Gardens at Acquia, one of the fears when they added - before they added Views was someone could make a query that could cripple their whole website and slow it down.
So if you sort of think of Views as limiting a selection and you’re filtering to limit what content you’re showing, you’re not trying to just vomit out everything from your site, then you’re pretty safe. There’s probably a limit as well. I spoke about this last week. When you’re adding a lot of displays, additional displays are actually loaded - when you view, for example - on my own website, you look at the Canadian list, you are also getting on any content that’s loaded for the other displays as well. So you might think just that. If you’re using displays, make sure there’s a lot of similar content between them. Caching is going to help there too.
Hannah Corey: All right. Awesome. The last question is can you filter the visibility of the block view by content type rather than by path patterns?
Heather James: You can, absolutely. I mean, in my case it wasn’t going to work because I was trying to change the users of - showed on the user profile but you actually totally do that. So I'm going to go this level block, for example. Instead of showing it on every page, I’m only going to show it by specific content types like I only want to show it on courses and recipes. It’s kind of the only place that levels is relevant too, for example. So I’ll save that and my level block no longer shows up here but if I click through to my course, for example, I’ll see my level blocks show up. Well, it’s actually interesting. This here is a taxonomy view when I went to the beginner list. This is just - excuse me - a list from the taxonomy. It automatically comes with the taxonomy module that’s core in Drupal. So what’s interesting is you might think “Well, I don’t like the way this looks. Maybe I want to change that with Views.” If you go to structure Views - it’s one thing I intended to show you. You can actually get an overwrite of taxonomy with this Views template that’s actually available to you. So it actually overwrites taxonomy. There’s also one for the tracker. There is one for - there’s an automatic one for archive. So definitely checkout some of those Views defaults. It might give you some more help too on using some advanced functionality in Views.
Hannah Corey: All right. Great. I think that’s it for questions. Thank you everyone for attending and thank you so much, Heather, for this great training presentation. Again, the slides and recording will be posted to the Acquia.com website in the next 48 hours. Please definitely signup for next week’s training course with Heather. Heather, do you want to end with anything?
Heather James: No. Thank you so much. I’m seeing this, Hannah. It’s a huge help. I’m looking forward. If people come next week and have questions as well, if they’ve prepared things and - I think, Hannah, you’ll be able to give the questions from this week and I can follow up on anything. There is one question I definitely will follow up on.
Hannah Corey: Yes. Definitely. All right. Great. Thanks everyone.