 I think we can start. Good afternoon. Thanks for coming. Last year I was here to talk about custom fields in Drupal 8. It's not a mistake, just one word missing there, okay? It's been changed to custom entities in Drupal 8. Right. I'm Deji Akala and I work for Katgeminar UK and I've been in the Drupal world since the days of 4.0. Something that was late 2005, early 2006. So I've seen the transition from 4 to 5 to 6 to 7 and to 8 now. Before we look at custom entities, let's talk about the entity itself. What's an entity? Well, you can say it's a thing or an object, right? And you can also consider that as something as property and behavior. So it's just like a class, you know? And a couple of years ago, there was a long discussion on that issue, use the term entity instead of object, right? And that's because they couldn't decide whether to go for object class entity. And if you trace the history of entities in Drupal, it started from the days of FlexiNode. And then CCK, then fields, oh, that's a good idea. You can just create something, a content app, add fields. And then that made life a lot easier. Then the idea of fields, then we graduate there towards entities. And then talk about fieldable entities and non-fieldable entities. However, Drupal 8 has sort of brought entities to a different level altogether. And then you find different types of entities, things like nodes, users, blocks, comments, everything is now entity, right? So it seems as if everywhere you look in Drupal 8 code, an entity jumps at you, right? So maybe time Drupal 9 comes out, or maybe 10, it's going to be entities everywhere. You can't work with entities, just like OOP, how should I say it now? Purists or gurus see classes everywhere. It means it's just one line of code. It's a class. So maybe we come to that entities everywhere in Drupal. And Drupal 8 also crystallizes entity types, right? There's a config entity type and there's a content entity type. And I would like to think of the config entity type as information about your site. And then content entity as information on your site, something that your users come to visit your site for no matter what that is. So they come for content and that's what they've come for, right? So we've got config entity types and also content entity types. And core comes with a number of this, a number of these config entity types and content entity types. We look at what that at config entity type does an at content entity type. So if you were to go on the core modules directory and then search for at config entity type, you see this one, right? Plus some other test types. But these are the ones that we actually need. You can see. And then the other side, you've got the content entity types, right? And if you look closely, you can see block content type on one side. And on the other side, you've got block content. You've got contact form identity type, contact message as the content entity type for that. There's node type, node. But there are some that have no um, counterpart on the other side. User is only content. You can see view config entity type on one side. So that means core has given us a lot, a lot built in, a lot's been built in. And let's have a closer look at the content entity type. You see that one, you can go from your entity type to your sub entity type and then your entity. For instance, node as entity type, right? When you go to your content types list, um, um, your installation, what you see there is the sub entity types, right? Uh, things like, uh, it comes with an article and page. Yep. So those are the two right. And then when you create a page, create an article, that's, that's like, um, that's, that's just the real entity. It's like an instance. So content types can be seen as a little field, right? A set of fields considered together. So you notice them and then you've got fields like you've got title, body, image tags and comments. That makes your article. And then for your, for your new, for your page, you can have that's just title on body. Maybe you want to create a news, right? News can then be tied to body image and category tags and where you can just select, um, the terms to tag the news item with. So node is the entity type. If you want to talk class is your base class and then, uh, article, the sub entity type, uh, your content type, your bundle can be seen as maybe subclass or a standard class. Uh, and then the article itself arsenal fan, maybe the title will be arsenal, same old, same old, right? So that's just the entity or just the, uh, the, the, the class instance. So yeah, right. And, um, um, the beauty of, uh, Drupal 8 and even prior, prior to that is that you can create your own content type, right? You can create it and in Drupal 8, it comes with only body fields, which is not even quasi. So you can pin that, right? Um, you can also, uh, uh, you can also add, add, um, add fields, right? To that and you can export them, you know, uh, if I had to go back, you can see, um, feed storage config, feed config. These are things that you can export, right? The configuration of your site, right? You can, you can bundle fields, right? And then, export them and then, uh, and then they've, and then we can, um, you don't, you don't, you don't have to write code. You don't have to do anything. However, you have to think about, um, the, the extras that call adds to your content types, things like, um, menu, comment path, um, uh, promotion to a front page or not, uh, or no front, the author and everything. And, um, country modules may also add some, some fields that you don't know about, right? So some people say, well, well, well, well, well, uh, I can use nodes everywhere. So that means I can just, uh, from, from, from, from alter out all those things that are not, uh, required. You don't, you don't want comments. You don't want, um, just like menu path. I can always, um, um, from alter them out. Yeah. What's all this fuss about entity then? Well, that's not cool. And, um, and also the code still gets brought anywhere. You're only hiding some of the, some of the effects of that. Um, right. So we've, um, we've, uh, come to the point now that there are some ways in which we can still use nodes everywhere, but we don't want to go that good. We just want to go with our, um, entities. You want to, you want to write your own custom entities. So how do we then start? I'll, um, um, we'll go over, uh, something that, um, I've been working on for some, for some time is still sandbox. It's, um, great book, um, application in Drupal 8. So one of the things to consider there is, um, how to record grades, right? How to record grades. Uh, for instance, you've got, um, a star. Okay. Uh, which is a distinction. And then you've got a very good. And then, and then B and then C and then EF. Um, yeah, also, it's not always that, um, a letter is used for groups, right? I know that in Polish, uh, we don't use letters. We have six, so you don't say, and then five, uh, but then that's also complex because you've got five plus. You go four minus four plus four. So these we can ask about letters. Just have to add back if you mind. And as it much dreaded two minus minus, you see, uh, yeah. So you also need to think about the, the grid ranges, right? For, for instance, maybe March 101, you can say 90 to a hundred is your A star, but for three to one, oh, it's 95 to a hundred. That's your A star. So you need to find a way in this grade book, uh, application to specify different ranges for the same letters and then, um, group them to, to, to, to get that, right? So, um, we're not, we've not come up with, uh, this too, right? Um, great letter set. That's a group of letters, right? That may be from zero to out to a hundred. You can have five ranges there, uh, of letters. And then for maybe for a different course, you want to have more letters, right? So you've got, so you've got this grid letter sets and then the grid letters. So your grid letter sets won't really have much, maybe just the label is enough. So, um, we use config entity for that one. Okay. The config entity type for your grid letter sites and for your grid letters, with then the content entity type. Uh, okay. What about the fields? Yeah. I've said label for grid letter set should be enough. Um, but, um, but for the grid letters, you need the labor, you need the description and also you also need things like the lowest grade, the highest grade and then weight. Maybe you enter them differently. You want to be able to adjust the weight. That's also the need to allow, if you, if you want to allow, um, others to add fields, to your content entity types. That's also something to be considered. So yes, it's possible. So that's another question you need to consider when you're talking about your entity. You want to make them fieldable or not? Uh, then you have to think about the, the forms, right? For hours, we probably need to just add edit and then the delete confirmation and then lists. We also have to have a way of managing the list, right? And we can have the list of grid letter set and then you can add anyone, edit or delete as you wish. So, um, in triple seven, you always start to think about this as an, oh, there's a module for that. I like that. Last year I mentioned it too. Okay. So, and then, and in your custom mode, you have to think of hooks to implement, right? Uh, there are things like a hook entity info, entity property info, the schema that's going to, where you inform Drupal about the fields that you, about, um, about the, about the database schema for your entities, right? And then maybe insert, update or delete hooks, right? Right. But, uh, in Drupal 8, it's a different altogether. So, that's, somebody gave me this statement after last year's presentation and, and I like it. That's a class for that in, in Drupal 8. You have to think class module comes in, but, um, it plays very, uh, little role in, um, in Drupal 8. Okay. So, um, like, like, like I said, um, you still need your custom module, but for your hooks, in most, in most cases, you will now start dealing with, uh, annotations, what, and then what's that? It's just a comment, a comment that has special meaning in Drupal, right? Uh, even in, even in code generally, you find it in symphony, Laravel, you find annotations. Uh, yes, you find that everywhere. It's comments with special meaning. So, I'll follow this in pattern as, um, as last year, I'll just show you some, some stops. And then we then look at the code, walk through the code. And if we have time, we can then add a few things to the functionality. So, yeah. So that's what an annotation looks like. I can see the comment, right? You can see at config entity type there. We'll have a look at that. This, this just stops, right? It just won't do anything at all. And for the grid letter, you can see the content entity type there. So that's a good starting point for us. Like I said, there are missing parts, which we will look at, we will look at later. That Drupal, that namespace, Drupal grid book entity, that's some, that tells Drupal where to find your code. Okay. Right. We're now moving closer to what's looking at, looking at some, some, some code now. So you still need your, you still need your info file. It's now Yammer file. And then you also, the modifier is very, very small, as you are going to see. In fact, that's, that's the only hook that needs to be implemented at all for this to, for this to work. You can see it's very small. So you end up with something like this. Okay. You can see there's a lot of fires there, but we'll have a look at them shortly. Okay. So let's have a look at this. Let me just show you the, so that's what this looks like now. Hmm. This is way too big. Sorry about this. I try to make this smaller. Okay. So let's just leave it as, as a command minus. Oh, command, command minus. Yeah, let's just, no, it doesn't work. Yeah, it doesn't work. It doesn't work that command minus. Let me try it. Let me, is it, this didn't work like two minutes ago. Oops. Yeah. Is that, is that any better? Any better? Yeah. Yeah. Sorry about that. Yeah, you can say, oh, this is no good. It's no good at all. Yeah. Yeah. Okay. Yeah. I think let's just leave it as, let me just remove this two bars, right? Let me remove the two bars. Yeah. Does that look better now? Yeah. Yes. Good. Okay. Right. So you can see that, so that it made. And then this one dashes the root and on top of the page, that's what you want there. That's what you want on top of the page when you go to that, right? No, I can't. We have just clicked on top there. Okay. Good. So here, these are just the parts. What hook menu is it going to use now? You now have that in the root file. We shall see what, what happens. Okay. Now the most important part, yeah, is here. So let's start with our grid letter set. That's the config, right? Now, that's just ID and the labor handlers. These are like controllers, controller classes that that's for the access controller. That's for the list builder. Like when you want to see the list of the list of grid letter sets. And then these deforms are here. Config prefix. That's when you, when you export, you find them, the fires is named your module dot config prefix. And then, and then, and then the ID of, the ID of the grid letter set that you've created. We shall see later. Bundle off. So our grid letter set is a config entity and then the bundles that will be grid letter set we, we've specified here as grid letter. Okay. The entity keys, that's what you, that's what identifies the grid letter set. We shall see where that comes in. And then this, these are links that Drupal will generate for us. And then we shall see how to refer to this later. Let me show you now. Let me show you that now. You see, you see, entity grid letter set list form entity grid letter set list form. You can see it here. You can see it. So that's the path. And when you go to that path, you will now see this, this help text there at the top. And then config export where you want to export. What would you like to export? This one is just, it's just like, you know, it's just like normal. That's what you've extended. You haven't done anything at all to it. These are just methods that we can comment out. And it still works, right? So, of course, the interface, let me, let me remove this interface. You see, it works because really just extended that, that class. Now, implements grid letter set interface. That's just, I've specified some methods that I want implemented in my class. Let me just quickly show what that's all about. And you can see it here, grid letter set interface. So, so this method must be implemented, but they're not essential for my config entity. They're not essential because I just want to find a way of getting all grid letters in a set nicely sorted. And then I just want to get a total of all grid letters, right? Just to demonstrate the possibilities. We shall see where this comes in later. Now, grid letter is more interesting. Yeah, I think it's manageable, okay? Now, you can see, it's the same at the right, that's the one that entity, the labor, you've got the handlers. Now, since we are storing some content, you need to, you need to tell car about, so that's the base table. And that's the data table. That's where the fields we now store their data. So you can see this are the entity keys. And then these are the same links, the same type of links, right? And then you want also to say the entity type, the entity type for this, the config entity type for this one, which is what we've specified before. Bundle off was grid letter, and bundle entity type is grid letter set, okay? All right. So now, these aren't the only entity annotation properties you can specify. I'll show you where you can find the others. You can see it's also the same. You've extended the content entity base. Remember, content entity type, you extend content entity base. And then as best practice, you also have to implement your interface. This is just a bunch of get us and set us for our properties, right? Remember, we're talking about properties and behavior earlier on. These are just get us and set us. But this is what needs to be implemented. If I comment this out, you see that it's going to tell me something is missing. You can see. So it determines this. Class must be abstract or implement method base field definitions, because I've extended that class, okay? And these, and these fields are defined here are my base fields, right? It's possible to also define default fields per bundle. Then you need to implement a different method. That's called bundle field definitions. I think that's what that method is called. So you can see this base with definition. That's the type and then you've got the label, the description, settings. Let me show you. You can also create entity reference fields. And this one is for the grid letter set. Here display options for the form. You've got the view, display options, how you want them displayed. If you want, do you want this field configurable from your, from your field display? I'll show you that where you've got manage fields, manage form display, manage view view display, which I see that in a second. So that, so this field will now appear in that list. And that's the lowest and that's the highest and that's your weight and some other things that you need, right? Okay. So these, so this method is the only one that's required, right? That's where you define your fields, right? And so you don't need to worry about exporting your field configuration, your field storage config, right? You just, you define them here. And, and when you, when you enable this model, these fields would be automatically created for you. Okay. So that's that one. Now, I promise to show where the, where you can see the, where you can see the, what is it called? The annotations. If you go to libdrupal core and you go to entity, you see something here, annotations, right? You go to config entity type. You don't see much here. However, if you read the comment, it says annotation properties of entity types are found on Drupal core config entity, config entity type. So you don't go there. It says config entity, config entity type. You can see it here. So you don't see much here. You can see config prefix, config export. These are the properties you want to export it. The ones we specified earlier on. But if you look at extends, you will see a lot more. You can see entity keys. That's the key of when you were looking at the annotations earlier on. You saw the entity keys, right? You see your ID. You see your class. There's more here. Handlers, array, links. So if you, if you go through here, you will see properties that you might be interested in in defining. You can see libdrupal core, entity type, bundle of. You can see all those ones. So that's where you find the annotations that you can use there. Okay. Okay. Let's quickly enable this because time is, time's really going. We're gonna, not a good day to be a goner. Let's go to DCL. By the way, I've set up this before. Hopefully it doesn't crash and burn. Oh, yes, we've got that. Oh, it's not, yeah, it's not, yeah, this is not the best. However, here you see grid letters, right? So you can see the total letters that was calculated first and that in that class. You can see default. I'll show you where that default is from in a second. Yeah, I'm just conscious of time, you see here. So we can list grid letters. There's no grid letter for us to see here. Yes. Now, I didn't show you where the, I didn't tell you there's going to be default grid letters. Did I? No, I didn't because I forgot. Now, let's go back. Of course, we know config, configuration files are, they go in this folder, config. So on install, whatever is here will now be created for you. So we can see model set, which is the config prefix we said later on. Default does the ID of this grid letter set, which is, and there is something that needs to be done. You need to tell Drupal about the schema for that something that says, now this has the ID here is type string and the label is ID, label is just mapping. That's to describe what's, what's in this, what's here, right? Okay. So when you install your module, you don't see that it goes to that config folder and whatever is there, it installs it for you. So that's why we got that. So, and I said earlier on that list of all grid letters sets, that was the, that's what's in the hook help that we implemented earlier on for this something. So yeah, here, least grid, grid letters, there is none. So let's add one. My favorite, excellent lowest, maybe we say 94.99 highest 100, which I don't think anybody can score if you're in my class. It's all right. So let's, let's just, let's quickly add a B, maybe B, let's just put that as 80, 85. It doesn't really matter whatever we put the adjustment to them or something. Oh, and then, oh yes, we need, we need an A, we've forgotten an A. So let's put that as maybe, was that, did we have 94? It doesn't matter. Anyway, this is just a demo. So let's have 85. We can put anything there. Yeah, let's just leave it like that. Just want to show that this can drag that, drag that. Yeah, so it stays where it was before. And then when you, yeah, you can see three steps. That's sort of grid letters. You can add a different grid letter set for let's say Drupal. Yeah, maybe you have, maybe you're running a Drupal course, right? And then you can, yeah, we don't, so there's no grid letters set. There's no grid letters for that one. Yeah, you can see. So that way you can bond to grid letters into sets and use them as you like. Okay. I also, ah, yes, I think I should, I should just demo this quickly. Now you can see here, it simply says grid letters. Yeah. If you go back, it says grid letters, but it doesn't tell you anything. So what we need is to do something. Ah, this is just, oh, let's just move this. Okay. You know what? I've got some there. So grid list form, where are you written? So in fact, this way you can change page titles, isn't it? Let's say list, right, grid set list form. Yeah. I think it's this one, hopefully. So you're not saying, so title, title callback, where you want to get the page, the page title, run the code here in this control, in this class, run that method, the page title. So, so you can see that controller. Sorry, guys, I think because we changed that. So let's do this. By the way, the code for this demo, I'll show you where you can, where you can find it. There are some other things that this is just introduction and to walk you through the code. There are lots of things that we've not considered, we've not covered at all here. So if we go here now, ah, that one is dead now. So that tells you where that one is. And then here, yeah, it's not here. This return loss is default, yeah. So you can then add for that one. One quick thing, you know, we're talking about fields, right? There's no way here for you to add fields to anything, right, to the grid letters, right? Yeah. But we want to be able to sort of do that. Let's quickly have a look at that. You need to do something to your annotation. You need to add a key there. Because you want this field, right? So, so that way you want to edit a grid letter set. So you want to be able to add fields to the grid letters in that set. Okay, so we shall see how that works. So that's all you need to define there. However, before you can see the links, when you visit that page, there's something you need to add to, yeah, that's still empty now for the tasks, right? That's for, secondary tabs in seven, six, that kind of thing. So that's now, you can then sort them out here in your Yammu Fire here, links task. So let's quickly, how are we doing for time? On battle? Oh, okay. That's no good. Yeah, well, we can see that. So we see that. So that's, this idea of the two places you need to change. Because we did the annotation change, we can just do something like that. So here now, hopefully, hopefully, there's something there, you can see my name from display, you can see everything. Yes. When you go there, this is no physical present yet. It tells you, you can do anything yet. You see, description lowest, highest. These are your base fields, right? You can only change them. You can only change the order because, remember the view display options in that bundle field definition, we said, true. That is why you want them to be able to change the order here. So let's make something happen. Let's make something happen. Let's add something here. I just said, I hope this works because, because yesterday, let's say Drupal camp field. It doesn't matter. It's just there. Yeah. Good. Yeah. So that's that. Now you can see form display. So you cannot change it. You cannot change the text. I don't know whatever you like that. And you can see that here. You can drag and drop anywhere you like and save. That's the demo. That was very fast. But yeah, we've, we've seen, we've seen step by step how to tackle this problem. Now, practically, how did I get into, into this, into fields, into entities, Drupal. What I did was a couple of years ago when Drupal 8, when there was some momentum, some code released, I found two contribute poll and profile, right? That was taken out of Drupal 7 core. I walked on them. As, as core was, was being changed, I was just learning trying to make them work, right? So I adopted those two modus and then as the code became stabilized, I was upgrading some of my own modus, right? I created a couple country field, a language field, plus, plus a couple of others, right? That are available. Address field also, simple address field for Drupal 8. And also, also, like I said, I've got a personal project called PHP Edu, right? That's supposed to be a model for Drupal, right? It's coming along. And this great book is part of that. So when this proof of concept works, then I can then upgrade the sandbox to a real model, right? So these are different ways I've, I've adopted to learn to get into Drupal 8 and also speaking to. So if you, if you are going to speak, then you have to show something, right? That's works. And luckily for me today, it has worked. So, yeah. So I'm going to quickly show you. In fact, this is not the only thing for, yeah, I hope it doesn't mind. Let me show you a couple of other things. Like I was saying, let's just use this window. We're not coming back here. So for great book, there is still a lot of concepts that have not been covered. So you can see there are more entities there, like a great category item, great score, lots of other stuff, right? Great scale. So if you're, if you're in education and you're thinking about Drupal 8, something like, talk to me afterwards, right? There's, there's stuff that you can, that you can work with. Good. Good. So you find, you find the past media, kind of like this year, 2016. And for the code that I quickly showed you, you find a bunch of modules there for that, for that, it is free, open source. Yeah. Yes. I do the cool stuff to Twitter, I don't tweet regularly now, but yeah, you can see me there. Yeah. Once again, thanks for coming.