Creating a Craft CMS Field Type
Craft CMS provides a bunch of field types as part of the core application. Some of the field types are specialized to Craft CMS functionality, like the Assets field or the Matrix field, and others you can get on the Craft Plugin Store.
As I mentioned in the last video, Craft CMS provides a bunch of field types as part of the core application. Some of the field types are specialized to Craft CMS functionality, like the Assets field or the Matrix field.
But others, like Dropdown or Table fields, can be customized with your data.
While these are the field types provided by default with Craft CMS, you can also add your own custom field types to handle data situations specific to your site’s implementation. Mostly commonly, you’ll find these custom field types in plugins.
For example, on CraftQuest, I use the Videos plugin by Dukt. Videos is a plugin that makes it easy to include videos from third-party sources, like Vimeo or YouTube, and have programmatic access to the video data.
This plugin provides a custom field type called Videos, which exposes the plugin’s functionality as a field in your publish layout.
In the Craft Plugin Store, there’s an entire category on Fields. These range from the Redactor WYSIWYG field to the Recipe field for more easily formatting recipe data, and to something as simple as a single category select field. If you want to share a custom field with others that they can use on their projects, then you do it via a plugin.
However, you don’t have to have a plugin to create a custom field. Sometimes a project calls for a specific field that collects or retrieves data in a certain way.
In that case, you would use a module as the delivery mechanism for the field type. If you haven’t built a module before, check out my course My First Craft CMS Module, which will teach you the basics of building a module.
We’ll also build a simple module in this course to house our custom field types but I’ll link to the starter module to focus just on the field type and nothing else.
Okay, let’s get started!
Creating a Craft CMS Field Type is made up of the following videos: