We’re going to use the Craft Module starter module that is available on my Github account. Installing it is as simple as following the instruction. Let’s walk through these together.
We want to focus on building our first field type for this course, so we’ll start with a simple pre-built Craft module.
We’re going to use the Craft Module starter module available on my Github account. Installing it is as simple as following the instruction. Let’s walk through these together.
craft-modulemodules directory in your Craft project. I’m going to do this in my CraftQuest project.config/app.php to bootstrap the module. composer.json file so that the class file is included in Composer’s autoload files. After that, we’ll need to rebuild the autoload files:composer dump-autoload
With that done, we should be able to load our site just as before. Our module doesn’t do anything yet, so Craft should just bootstrap it and then continue on as normal. No errors is good good news.
To prepare for our custom fields, let’s create a fields directory inside the module src directory to hold the custom fields code. Suppose you’ve followed along in my other courses on extending Craft. In that case, you will recognize this pattern of creating directories inside the src directory for each component we are adding to Craft.
craft-module
├── README.md
└── src
├── CraftModule.php
└── fields
Inside the fields directory, we will create a class file for each field type that we want to make.
In the following video, we’ll work on our first field type for a world language dropdown.