Join Tom Geller for an in-depth discussion in this video Create new content types, part of Drupal 8 Essentials 2: Building Out Your Website.
- So far we've created content in the form of articles, basic pages, and forum topics. These are all what Drupal calls content types. Each one is a sort of template for individual pieces of content which are called nodes. These three content types are all defined by Drupal itself. To get you started creating content right away, but you can also define your own content types, here's how. To start, go up to Structure and click Content Types. And here are the three content types that I just mentioned.
You'll notice that next to each of them, there's a description and a pop-up menu of different operations you can perform on them. We'll go through some of these in this course. But for now, I'm going to add a new one. I want to have a directory of artists who are exhibiting at our fictional museum so I'm going to call this Artists. The description will be information about artists connected with the museum. And instead of seeing Title, when someone fills out this form, I want it to say Artist Name so that it's clear that it's about a person not some random piece of content that has a title.
And down here, we can have some submission guidelines. For example here we might have an intern who's filling this in and might not have all the information so I'll just say fill in as much as you can. Then we have several options in the metadata. For example, when I'm creating this directory I don't want every node that's created to go to the front page like a blog post, so I'll make it so it's not promoted. You could also, for example, make it so that it's not published when it's first created. That would mean that an administrator would have to go back and approve each piece of content.
The display settings we'll keep the same, we want to show the author and date and nothing changes in the menu settings. Click Save and Manage Fields. When you create a content type, by default it only has one field. This one body, well technically it has two, it has the title and the body but this is the only one you can change. I'm going to click Edit, and instead of body, I'm going to call this the Biography. Again, it's a person not just a random piece of content. Here again you could add Help text. You could also make this field required, or put in a default value which is automatically entered when you create the node.
We'll talk more about what Summary Input means at another point in this course, but for now, I'll click Save Settings. Now I'm going to start adding other fields. For example, since it's a person, let's add a date of birth. We have a wide variety of types of fields that we can add. In this case, it's going to be a date. We don't already have a date field we want to reuse, so I'm going to call this Date of Birth and save and continue. Here again we have a variety of options and this will vary depending on the type of field you're adding.
In this case, it's a date of birth, we don't really want to know the time so I'll just say Date Only. And there's only one date obviously, so I'll save those settings. Then once again we have some additional options. I'm just going to say save settings since I don't want to change any of these. Now I'm going to add one more field so we can have a picture of the person in question. Add Field That's going to be an image. And I'll call it Portrait, and save and continue.
There's a nice little option here when you add an image, you can have a default image so that if for example you don't have a picture of the person, you can have something that says I'm sorry, we don't have a picture. It could be a generic picture of a person or whatever you want to do. In the exercise files for this course, you'll find such an image. I'll get it by going to Browse, and there's our No Image Available jpeg, I click it and open. And as usual you can add alternative text in a title for people who have vision problems. And I'll save these basic field settings.
Then as before we have some additional settings available for us. One that I'm going to change is this minimum image resolution. I don't want anybody uploading these thumbnails that then get blown up and look terrible so I'll say it has to be at least 400 pixels by 400 pixels. One other thing I'm going to change is the File Directory. If you don't change it, it gives the year and the month in which the file was uploaded. I think I'd rather just put it into a folder called Artist Portraits.
Scroll to the bottom and save settings. Now that we've created our content type, let's add information about one of our artists. Again, you'll find this text in the exercise files for this video. To get started, we go up to Content and Add Content and there's our content type Artist so click that. Now I'll copy and paste the information and add the image and I save it. And there we go. We have the person's name, their bio, their date of birth, ooh, and then we have this portrait which is way too big because the image itself was way too big.
I can fix this by going back to the content type and changing this image style. I click Structure, Content Types, and Artists but instead of Manage Fields, I'm going to say Manage Display. And for portrait, instead of it being the original image I click this little doohickey here and change it to large and update and save. Now when I go back to that node, which I can find by going to Content and clicking on it.
So now the photo looks the way we want it. But the date of birth doesn't. It has the time even though we said that we didn't want that. To fix that, I'm going to go back up to Structure and Content Types and Artists and once again Manage Display. Next to date of birth, I'll change the format by clicking on this gear and change it to html date Then I click update and save. Now let's go back to our node and see how it looks.
All good. Finally and as always, when we change our site's configuration, we should check the list of permissions to make sure that the right people have access that we want to grant. To do that, go up to People and Permissions and I'm just going to search on this page for the word Artists. We can create new content, delete any content delete our own content, yep the administrator has all of the things that they need. If we wanted to give them to other roles, we could do that here as well. Now although this wasn't a very long video the ability to set up your own content types is a huge feature of Drupal and it's one not found in every content management system.
In other videos, you'll learn more about the types of fields that are available how to change how they look to content creators and how the results are presented to the people who visit your site.
In these tutorials, Tom Geller helps new Drupal designers change the layout and design elements of their sites, control visitor interactions (including comments), arrange content in user-friendly "views," and expand the site's capabilities beyond what's available in core Drupal with Drupal modules. In all the steps you'll learn best practices to ensure your sites remain streamlined, secure, and up to date.
If you want to start from the beginning and create your Drupal site from scratch, check out Drupal 8 Essentials 1: Getting Started.
- Grouping content into categories
- Managing comments
- Adding discussion groups
- Customizing fields and image styles
- Adjusting menus and navigation to help users
- Adding new features with Drupal modules