 Hey, so hello and welcome to this presentation on managing your content model in Drupal. Now, just a bit about myself, my name is Ivan Zujek and I've been a Drupal developer. And I think my Drupal profile is just about six months or four months from ticking over 15 years, which is a bit crazy because I've seen other people with profiles that are 20 years old. And I remember when it was just 10 years. So pretty crazy. I also write a fair bit over at webwash.net. So if you want to learn about Drupal, I am planning to write about other technologies because I've been playing around with a lot of other technologies. But for now, it's Drupal and I've got a whole bunch of free courses on there and mostly tutorials as well. And so the agenda for this evening is broken up into four parts. So this session is broken up into four parts. We'll first look at how content is stored in Drupal. So I'll just take you through the process of creating a basic page because one thing I've learned, especially with my courses and producing videos for the general public is that even people get stuck at that level as well. The next thing is we'll look at content types and fields and then we'll look at taxonomy, how to categorize your content and then we'll look at managing media assets and finally we'll look at grouping fields using paragraphs. So let me now jump out of this because the rest of it is gonna be live. So it's gonna be fun. Just give me one second while I prepare things here and I do hope there's not much background noise because the kids will be starting to go crazy very soon. Okay, so let's get started. All right, so right now, so here I've got a stock standard Drupal site and the only thing I've done is I've installed Drupal using the standard installation profile and I've also just created three articles and that's it. And I wanna show you now how to create a piece of content. Now I'm not gonna cover how content is stored in Drupal in depth from start to finish but I'll just show you how to create a basic page because if you are using Drupal, the chances are you wanna use it for its CMS capability. So most of your content will be accessible via a page. So somebody goes to a path and they will see your content. Now creating a basic page or an article which I'll show you now is pretty simple. Once you are logged in, go to content and then add content and then here you can select your different content types. Now, if you've installed Drupal using the standard installation profile, you will see these two. So that's article and basic page. I'll click on article and I'll create a test article title and I'll put in a bunch of dummy text and then we can tag things as well. So tag one, tag two and finally I do have a collection of reusable assets that I always have available where I can upload an image and I'll call this one image text and then we'll go ahead and click on save. And here you can see the title, the image and the body and then we have the tags here below it. And the page is accessible up the top here. You probably can't see that in the recording because it's too small but the path to it is node slash four. And of course that path can be changed using path aliases but that's a whole other session in itself. Now, if we go and edit this content, you can see that we have a title, body, tags and image field. Now, the content itself is stored in fields and a field is broken up into three parts. The field type, how the content is stored. Is it an image? Oh, sorry. Is it a, well, yeah. Is it like an image? Is it an integer? Is it text? And then you have other crazy types of fields and then you have the field widget which is the form element here, how the content is entered in. And you can see that we have basic form elements for title and then we have crazy form elements for body which is a full text area and then we even have an auto complete down here. So if I type in, should we be able to type in again? Yeah, tags is an auto complete element. So we have all sorts of different elements and then finally we have the form matter which simply renders out the content to the end user. Now, when it comes to your content model, Drupal allows you to create different content types. And if I open up another tab and then go to content add content, you can see our two content types right here, article and basic page. And the best way to think of a content type is that it allows you to contextually group fields together because it's the field that actually stores the content but a content type just allows you to contextually group fields. So for example, if you wanna store events, you could create an event content type but then you need to think of all the fields. So when you think of an event, you need a title, you need a body, you need an event start date, event start or end date, you need an event location and things like that. So it's always good when you are defining your content model just to think of all the content types you're going to use and also the fields required for those content types. So that is the theory of how content is stored, I've skipped a large part of entity types and fieldable entities and the difference between content and config, that's, yeah, that goes beyond. That's for another presentation but most of your content will be content types. So now let's go ahead and create a content type called product because let's just imagine we wanna promote products on our website and this product will have three fields to begin with, a product summary, a price and also a product type. So to create a content type, all you need to do is go into content, content types and click on add content type and I'll enter in a name here called product and then I'll enter in a used for product description, useful products, but you can put in something a bit more original than that and then here you can configure your content type. Now these can be changed later on, you don't have to worry about it but things like the things that I normally do is I disable previewing because that causes more pain than it's worth. I also remove promoted to front page, remove that and also remove it from the menu system settings because this being a product you're not gonna add it to the menu and if you are, you can add it in manually. And now from the manage fields page we can create our fields and straight away you can see that we have a body field. This body field is automatically created. It is programmatically created every time you create a new content type but if you prefer, you can go ahead and delete it. It is not required but it is a nice best practice because if somebody takes over a Drupal site every Drupal site builder knows what the body field is there for but I've worked on sites where we don't actually use it but in this case I'll leave it in there and now to create a field all you need to do is click on add field and then from here you have from the add a new field dropdown you have all of these field types and as I mentioned, you have basic ones like a Boolean which is a true and false if you wanna add in a checkbox then you have comments which adds whole commenting functionality with a single field and then you have date and email and so on and so forth but for this one, which one are we creating the product? Yeah, the product summary what I wanna do is create a text field for this product summary. So for that, I will select text plain long because long being a text area if I was to select plain it'll be just a text, just an import field. Now you may notice that there is formatted and there's plain, what is the difference? The difference is formatted allows you to format the text so you can underline it, you can create links you can make things bold. It adds the editor on top of the element so the CK editor but in our case, being a product summary we'll just leave it as a basic text field. So label, I will enter in the name of the field. Now quickly with the machine name so the machine readable name once you create the field, it cannot be changed. The label can be. So if you're very pedantic like myself where I spent a fair bit of time figuring out the correct machine names make sure you think about the machine name because you can't easily change the machine name like you can change the label. Of course, if you wanted to write custom code you can migrate data from one field to another and do it all in custom code that you can do but once you click on save and continue you're stuck with the machine name. And then from field settings you can change the allowed number of values. We will leave that for now and come back to it in a second. And then from the field edit page you can add in help text you can make things required and then you can put in a default value. We'll just keep that as it is. Then again, let's put in the price field I'm just looking at my notes here price field and I will select for this one I will select the float. Again, I'll put in the word price and then we'll leave number of values as it is and then here we can specify we can actually control specific settings for the field. So each field type comes with its own set of options. And here I'll just put in prefix of dollar sign and a suffix of A U D. Of course, you wouldn't want to do this if this was a proper e-commerce site you want to be dealing with cents instead of dollars and things like that of course this isn't a proper e-commerce site. And okay, so that's price now let's add in the product type and this is going to be a select list. So from adding a new field drop down we will select list text and then this one will be product type and straight away you'll notice that we get this new option called allowed values list this is where we can define the list of options. So to define the list of options let me just copy this across because I've already done it and all you need to do is specify the key and then put in a pipe and then you can specify the label as well. If you were to remove the label then this value will be used for both the key and the label but I like to specify the label oh let me just do that again, sorry but yeah, let me fix that up, okay I like to specify the label because later on and I'll show you if you want to change these values you can change the label but you can't change the value the key sorry in this case if it's used so that's just something to be aware of so always just chuck in a label and then if you want to allow a product to have multiple product types but in this case you only want to allow one product to have one product type then you'll change this number of values to multiple values and then if we scroll down here in the default value we can see our select list, okay so we've fleshed out our three fields let's now open up a new tab go to content then add content and then here we can see our fancy new content type let me just create a test product here we can add in a whole bunch of dummy text I think there is an actual extension I can set up or I can just go generate right click generate dummy text I'll just chuck in a summary as well I'll just put in here so we know the difference product summary and then let's put in a price and let's select a product type and here we can see our title, body, summary, price and product type pretty simple now if we go back to edit something that you may want to do and well I know I do on pretty much every Drupal site I work on is reorder these form elements and you can easily do that by going back to the content type and then click on manage form display this allows you to control the widgets on the field so straight away you can see that we have all of these extra fields and let's move well no we'll leave body there but let's move product summary, price and product type and click on save and then if we go back and refresh now take note of the product summary price and the drop down we can straight away see that it's been moved up now one thing to be aware of because this catches many people off guard is that these options on the right so alias, authored information, promotion options you can move these as much as you want but they are essentially hard coded to the right now of course if you were to put a form all in there you can go in there and change it and do whatever you want but from this UI you're pretty much stuck with where it's at but all of your custom fields can be moved around and another thing I also mentioned and I don't have this in my notes but just came to me now is that the title property is hard coded if you have a look here you can't see title but you can see it here and you can see it up the top here if for some reason you do not want the title filled you can simply drag it all the way down to the bottom and disable it so you don't need the title there even though it's technically hard coded on the entity if you look in the code it's there but if you don't want it you don't need it which is good okay so that is how you create your content type add in a bunch of fields manage the form display now I'm just checking on time I'm going okay and now let's look at the number of values which I mentioned about five minutes ago and I said that we'll come back to that so let's go to manage fields and I'll go to price and then edit and then click on field settings straight away you'll notice that we get a message telling us that the field has data in it and the settings cannot be changed well this message isn't 100% you can change these settings but it just depends on how your content is stored now if we were to change this to unlimited this will allow us take note of the single import field for price right here if we were to refresh we can now add in an unlimited amount of values a field in Drupal can have multiple values and then if we click on save we can see our 1, 2, 3, 4, 5 values here now let's go back to the field settings if we were to change this back to 1 now remember we have 5 values in the field if we were to change it back to 1 now it's going to tell us that there is one entity with two or more values in the field if we were to change this to 5 because we only have 5 values it'll allow us to save it but as soon as we change it to say 4 it's going to complain about it so to work around this the only option we have is we need to remove one of the values and the way you can do that is by just removing it, saving it Drupal will then go ahead and delete it and then we can come back here and save the field so that's something let me just quickly fix this up while I talk let me just bring this back down to 1 so that is something that I see a lot of people get caught up on because if you read this message you think nothing can be changed but in actual fact it can it just depends how your content is stored okay so now let's move on to entity reference fields because if if you've done any type of Drupal site building eventually there will be a need to create relationships between your content types and Drupal comes with a field called an entity reference field which allows you to reference any type of entity and in this example let's just imagine let's just imagine we have a whole bunch of articles and on the product field we want to link over to some related articles now to do that it's pretty simple all we need to do is click on add field and then from the add a new field drop down under reference we select content because the content type is a well the entity type is called content so we can just click on content and I'll call this one related articles and make sure the type of item to reference has content selected because that's the name of the entity type we want to reference now you cannot you can, how can I say it you can only reference one type of entity type using the core entity reference field a field cannot be configured to reference a content entity plus a taxonomy term and also a user now there is a third party module called I think dynamic entity reference which allows you to reference any type of entity from a single field but using just the core module using the core entity reference field you have to specify which entity you want to reference and then that is locked in and then from the allowed number of values I'll change this to unlimited so we can select multiple articles and then I'll scroll down and from content type I will select article because that's the only content type I want to select but you can select multiple content types of the same entity type so you can select the same bundle from the content entity type