Adding fields to content types
Video: Adding fields to content typesAdding fields to content types provides you with in-depth training on Web. Taught by Tom Geller as part of the Drupal 7 New Features
Adding fields to content types provides you with in-depth training on Web. Taught by Tom Geller as part of the Drupal 7 New Features
In Drupal 7 New Features, author Tom Geller demonstrates changes to the Drupal 7 administrative interface and other enhancements that have come out of its three-year development period. This course covers its simplified installation process, new themes that will help kick-start design projects, the customizable shortcut bar that puts often-used commands in easy reach, update procedures that leverage its browser-based interface, and a new way of defining fields to create complex content types without additional modules.
- Configuring the new Dashboard
- Using contextual link controls
- Exploring new themes
- Reviewing the new modules
- Understanding the expanded block system
- Using images in content
- Allowing users to delete accounts
- Testing modules with the Testing module
- Building themes using Drupal Gardens
Adding fields to content types
In Drupal 6, if you didn't have the module CCK or Content Construction Kit, you essentially had to make do with the basic Story and Page Content types. You could add others, but you couldn't have any fields to them. For example, for an image or a product price or a street address. Drupal's developers took the hint and the bulk of CCK is now part of Drupal core. The whole thing is not there, but rather its fundamental parts have been abstracted and added in, and what's now called the Field API. Because the way Drupal 7 handles fields is an evolution from CCK, we'll compare it to Drupal 6 with CCK installed and all of its modules enabled.
Remember though that almost none of what we are about to do is possible in Drupal 6 without CCK installed. If you've worked with CCK before, this will all seem pretty familiar in Drupal 7. To demonstrate, we'll create a new content type in both Drupal 7 and Drupal 6. In Drupal 7, you do that under Structure and Content types, and in Drupal 6, it's under the Administer, Content Management, and Content Types. This page looks pretty similar, once you've CCK installed of course so that you see the manage fields links over here in Drupal 6.
So we'll just create a content type in both of them, by clicking Add Content Type and we'll walk through this and call it a Vacation package, doesn't really need a description, and as I mentioned in the "Creating content" video, we now have these vertical tabs over here on the left. I am just going to walk through those a little bit right now. First of all, you can change the Title field label, so instead of being called Title, it might be called Location, if it's a vacation package for example. You can force people to preview their node before they actually committed to your site by changing this Preview before submitting, and you can add submission guidelines.
There's nothing new about that in Drupal 7. Publishing options are all pretty much the same as in Drupal 6. Display settings is quite new, and you now have the choice on a content type by content type basis as to whether it should say written by so-and-so on such-and-such a date. I'm going to turn that off for our content type, as I usually do for most of them, except if they're a news story or something that I want to have bylined. A blog is a good place for author and date information. In the "Creating content" video, I sort of glossed over Comment settings, when you're actually editing a node.
That's because most of those happen in the content type. Click on Comment settings and you can see the different controls you have. It's actually slimmed down quite a bit from Drupal 6. Let's take a look at those. Scroll down to Comment settings and you have all of these radio buttons. I always found it quite confusing, so I'm really very happy that they spent some attention on getting this more understandable. Then we have Menu settings. This is something new in Drupal 7. You can choose what menus are available to put nodes of this content type into.
That's good because in Drupal 6, when you created a node, if you want it to put it into a menu, you then saw a list of every available menu option, which is a huge list. So now you can just say, okay, you can only add nodes of this type that have links in the Main menu or the Navigation menu, whichever you like. I'm just going to save this content type in both Drupal 6 and Drupal 7. So again in Drupal 6, I'll go up and call it Vacation package. Here we have to type in the type, which we didn't did in Drupal 7.
vacation_package, no description. I'll leave everything else as it is and say Save content type. Now that we have our content type set up, we can start adding fields. In Drupal 6 and Drupal 7, it's pretty much the same. Manage Fields. Now you might have noticed on the previous screen, we also had a link Manage Display. We'll get to that in just a moment, but you also see a tab up here for it as well. The first thing that you notice on this screen, which is different from Drupal 6 with CCK, is the Body field is now editable.
In Drupal 6, you couldn't really do anything with it, as you see it's grayed out, but here you can treat it just like any other field actually, and in fact, you can delete the Body field, so all you have is a Title and any custom fields that you've added. I'm going to add a field. I'll call it Price, field_ price. The type will be called Decimal and then it'll just be a Text field and save. I'll do the same thing on Drupal 6, scroll down. New field is called Price, field type is Decimal and Text field.
Most of the settings for a specific field are pretty much the same and I'm not going to go through all of them. The one thing to notice is the Drupal 7 sometimes breaks it up into two screens instead of one, which is a little bit easier, because when you look at Drupal 6 with CCK, you are sometimes really overwhelmed with all these things and there are things that you have click in order to see the settings and it goes on and on like that. I'm just going to keep the default settings in both cases. In Drupal 7, I'll click through and then again I have to go and click a second time, since it was broken into two screens.
There, now we have our custom content type with a custom field. In both of course, you can move it around and save it and you can go back and edit it and delete it just as before with Drupal 6. The next different thing is this Manage Display. They exist in Drupal 6 under Display fields, but it's more flexible now. For one thing, you can set up custom display settings down here, so that this field will appear differently, whether it's in full content or in a teaser or RSS, or if it shows up after being hit with a search.
We won't go through those settings, but as you'll see, when you click any one of these, a new button appears up here and then you can select exactly what you want with that field in that context. The final thing that's different in Drupal 7 on the screen is Comment Fields and Comment Display. You can actually change the comments in response to a node in very much the same way, so instead of just having one big place where people say, "oh, I think this is great," they can have multiple fields. So how do you rate this, what you think about it, who have you recommended it to, what sort of person do you think would be good for, and so forth? And those are handled very much like the node itself.
Once you've created a content type of course, you might want to see how exactly it works. Well, let's go ahead and add a node of the type that we just created. We see Vacation package. Click through, you see Title, Price, Body. Basically from here on edit works exactly the same as in Drupal 6. You just have more options for setting up the content type itself. Now, a lot of this video is not about content types per se. It's about something called Field API, and that actually goes on much further than we've covered here. We got a taste of its benefits with the way that you can add fields to a content type, but it's not just for that.
User profiles and taxonomies also benefit from the field API. All of these things are something that are now called entities in Drupal and they have so to speak equal citizenship and that you can manipulate them equally well. This is possible because of something in Drupal 7 called Entity Query API. This is a big deal, even though it's something that we as administrators might not see. Drupal's creator Dries Buyaert called the biggest architectural change in the history of Drupal. Now that's a big thing to say, and he said that in July of 2010.
From my point of view as an administrator, it just feels that Drupal makes more sense. From what I've been told, it wasn't easy to implement in Drupal 7, and I for one appreciate all the hard work that Drupal's developers put into making it happen.
There are currently no FAQs about Drupal 7 New Features.