Adding fields in Drupal 7

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Drupal provides an incredible array of different styles of fields we can use to extend our content types in this tutorial we're gonna start learning how to add fields to our content to get started we're going to walk through to the most basic yet most commonly used types of fields those that can be used for storing simple text and numbers walking through how to use these basic fields will give us a good foundation to work with more advanced ones which we'll cover in later videos so join me as we learn how to start extending content types with fields in a previous video we create a new products content type for our demo sites we use just the two default fields title and body we can see them by going to our node edit page now we did rename them we named title to product name and body to description but they're still just the two default fields but now let's say that our site product owner wants to extend the types of information that we can add to our products let's say for example that we need to add a model ID to our product content type this is the perfect use for fields so let's go ahead and add a new field to do that we're going to go to structure but I'm interesting a little different I'm actually going to open this up in another tab and I like to do this so that while I'm working with my content type I have it open in this tab but then I can see what changes it's making to my note edit form over on this tab it's just a little trick that I like to do while I'm building content types so they flip back over here and run structure I want to click into content types I go the content type that I want to add my field which is the product one and then I go to manage fields and we see that down here is where I can add a new field in a previous video introduction to fields we talked about that the fields module does three different things it gives us a place to store data that's what this drop-down is about how do we want to store the data it also gives us a user interface widget on how we want to input the data that's what this element is here and then the third part is it gives us a way of outputting the data that's actually over in this tab in a slightly different area we'll look at that at the end of this video but for now let's go ahead and add our model ID field so the first thing to do is put in our name and then over here we see another field I'm gonna go and type something in right now and see we've got some more strict rules about how we use this I'm just gonna go ahead and put in model you see I put in the same thing but the key to it is that I've used a smaller set of characters once it can be saved into our database properly can be saved out to files and so it's something that's usable for Drupal to refer to this field internally you don't have to worry about the technical parts of it too much just know to follow the descriptions and special characters that it says right here so now I'm going to go ahead and I'm gonna select a field type for a first one we're just going to want to store some text we see that we've got all these different options I'm just going to go down and select text for now and now we're going to get a different set of selections over here based on what we select as far as what we want to store for text we only have one option a text field so we're going to go ahead and click Save so now we come to a screen where fields wants to know a little bit more about how we want to store this data for text field it only wants one piece of information what's the maximum number of characters that we might want to store for our model IDs they're never going to be more than 20 characters long so we'll go and put 20 and save the field on this next screen fields is going to give us the ability to customize our user interface widgets first thing it wants to know is what do we want for our label this is just copied from what we put in before so it's fine we'll leave it alone then we can say do we want this field to be required or not for our use case it's a model ID it's pretty important so we want to be required the next is the size of our text field before in the previous screen we said we only wanted to store 20 characters so it doesn't make sense to have the size of field any bigger than 20 so we'll go ahead and enter that in the next part is do we want to allow only plain text or do we want to do any filtering plain text is fine here we want to enter some information to help our content authors out so let's just say model ID from the catalog so we scroll down we also can do a default value we're not going to have one of those for our model ID so we leave that alone and this is really another interesting part of fields down here is we can select the number of values we're going to see how this works in a second so I'm just gonna leave it set to one I'm gonna go ahead and save we're now done creating our new field but one last thing I want to do is I want to go ahead and drag it up and reorder it and put it above our description I'm now going to click Save and now if I run back over to my node edit form I do our refresh and here's my model ID so I can go ahead and put in blue widgets a1 scroll down click Save and here we see our new field has been added right here now let's take a quick look at how the multiple values option works to see it I'm going to go ahead and reopen our node edit form and I'm going to flip back over to where I'm editing my content type I want to change the model field so over here I'm going to go to edit I'm going to scroll down and change this number of values to something like five do Save Settings run back over to a node edit form hit refresh and now you see I can put five different elements in here so let's say for example I want to put in blue widget Oh - and I can change the order of these if I want to the other thing that's kind of neat is that's run back over here to edit and now let's set this to unlimited click Save Settings go back over here and we do a refresh and now we see is that I've got my original field I've got one additional field and I have this add another item button so if I need to add three I can put a second one here and then just say I want to add another item and that way I can put in as many as I want or as few as I want it's a nice little option that allows us to make this kind of adjustment I'm going to go back and just change it back to our original one value setting save settings refresh and we're back to the way it was now let's say that the product owner comes back and they want us to add a price to our product type well to do that we can simply go back over to structure content types and then we click managed fields now we're going to run through the same thing we did before except this time we're calling it price put in a machine name of price and here in our drop-down if we wanted to we could select a texture miss down the bottom but because this is a number we might want to do some math on it I'm going to go ahead and select a decimal type here once again the only type of interface widget we're given is a text field so we're going to go ahead and leave that one and click Save now you'll see we have a little bit of different information here on how we want to say this number so basically what type of precision scale this information is fine so I'm just going to go ahead and leave it and save our field settings now we go through our UI widget settings much of this form is going to look similar to way they did for our text field but there are some things are going to be different because we are doing with a number field now so the label is fine I'm going to go ahead and require this under help text we just want to give our note authors some information to help get the right information in so I'm just going to put retail price as we scroll down we see that we now have some additional things such as we can put in a maximum amount a prefix and a suffix I'm gonna go ahead and and put in a dollar sign since we're dealing with money and for suffix I'm going to go ahead and put in USD because that were you know if US Dollars again I could put into fault I'm not going to do that I'm going to go ahead and leave one value and once again we get this precision information I'm going to leave that alone and click Save Settings once again I'm going to reorganize and drag this up here above our description and click Save run back over to our node edit form click refresh and here we see of our price with our prefix and our suffix so we go ahead and put in a price of $26 click Save and of course here's our pricing information on our node now that we've added a couple fields let's take a look at the third part of what the fields module gives us the ability to manage displays I'm going to go ahead and leave the node view open tab and run back over to our other tab and work on manage display here I can set various different settings so let's say for example I want to do inline labels and I want to move the model and price above our description so you just drag and drop and click Save run back over to our node view click refresh and now we see that the model and price fields have been added above our description and that we have these inline labels in this tutorial we work through how to add to the most basic fields to our content type a text and numeric field well there are many more advanced fields as we'll see later these two are the most used on most websites additionally much of the workflow and settings were used for these two basic fields will be the same for more advanced ones in the next tutorial we'll look at how to input text and numbers using a controlled list and how Drupal intelligently helps you manage elements based on usability best practices
Info
Channel: Tom McCracken
Views: 17,547
Rating: 5 out of 5
Keywords: drupal, drupal 7, cck, fields
Id: Y0YNKTpaLiU
Channel Id: undefined
Length: 9min 58sec (598 seconds)
Published: Wed Mar 30 2011
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.