Creating a custom field type
Field types are defined using the plugin system. Each field type has its own class and definition. A new field type can be defined through a custom class that will provide schema and property information.
Field types define ways in which data can be stored and handled through the Field API on entities. Field widgets provide means for editing a field type in the user interface. Field formatters provide means for displaying the field data to users. Both are plugins and will be covered in later recipes.
In this example, we will create a simple field type called realname
to store the first and last names and add it to a comment
type.
Getting ready
This recipe adds a field to a comment
type, which requires the Comment
module to be installed. The Comment
module is installed by default with a standard Drupal installation.