1. Creating a new field type class
To be able to create your own class derived from an existing Sitecore field type, you must first find out which Sitecore class is used for the field type you wish to extend. All available field types can be found in the core database under /sitecore/system/Field types, grouped the same way as in the field type selector dropdown that the template builders use.
Now you have established the type you want to derive from, find out which class is used for that specific field type by looking in the Control field (for example, content:Checkbox). The content prefix refers to the Sitecore.Shell.Applications.ContentEditor
namespace in the Sitecore.Kernel
assembly. The vast majority of all Sitecore field types reside in that namespace.
Note that the prefix can be traced back to the controlSources section in the config. There, you can match them to the related assembly and namespace. You now have the necessary information to create your custom field type class. With this information, you can set up a class in your solution by inheriting the built-in field type.
By using dotPeek
(or another decompiler), you can examine which methods you wish to override to achieve the required altered behavior.
2. Exposing the field type
To be able to reference your new field type from Sitecore, you need to create a config (section) in which you expose the namespace, assembly and prefix. An example config follows, based on the sample code above. Example:
3. Create a field type in Sitecore
To be able to use your new field type in Sitecore, it needs to be added in the core
database, in the same place you found the field type you are inheriting from: /sitecore/system/Field types. It is recommended you create a separate folder for your field types. They will then also end up in their own section in the dropdown.
The best way to create your field type is to copy the field type you're inheriting from into your folder. After copying it, you need to replace the value in the Control
field. The format for this field is <prefix>:<class name>
. For our example, this would result in mif:ProductSearchList
. You can now start using your newly created field type in your templates.