Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Adding fields to content types

From: Drupal 7 New Features

Video: 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.

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.

Show transcript

This video is part of

Image for Drupal 7 New Features
Drupal 7 New Features

29 video lessons · 7928 viewers

Tom Geller
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Drupal 7 New Features.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.