Types of configuration mapping fields in Drupal and when to use which

I was creating a tutorial on configuration entities when I stumbled upon a image field which I had specified as an integer instead of array. Therefore I thought it would be useful to provide you a table with all the types and when to use which. 

Example of a configuration schema

book_preview.*:
  type: config_entity
  label: Book preview
  mapping:
    id:
      type: string
      label: ID
    book_reference:
      type: integer
      label: 'Book node reference'
    cta_image:
      type: array
      label: 'Call to action image'
    cta_description:
      type: text
      label: 'Call to action description'
    cta_link:
      type: string
      label: 'Call to action link'

Types of configuration mapping fields

Type Description When to use
string A single line of text. For simple text fields, such as IDs, labels, descriptions, and filenames.
integer A whole number. For numeric fields, such as node IDs, user IDs, and quantities.
boolean A true/false value. For fields that can have two possible values, such as enabled/disabled, visible/hidden, and required/optional.
text A multi-line text field. For longer text fields, such as descriptions, articles, and code snippets.
array A list of values. For fields that can contain multiple values, such as tags, images, and files.
config_entity A reference to another configuration entity. For fields that need to reference other configuration entities, such as nodes, users, and taxonomy terms.
config_object A reference to a configuration object. For fields that need to reference configuration objects, such as system settings and module configuration.
email A valid email address. For fields that need to store email addresses.
url A valid URL. For fields that need to store URLs.
date A date and time. For fields that need to store dates and times.
datetime_immutable A date and time that cannot be changed. For fields that need to store dates and times that cannot be changed, such as the created and updated dates of entities.
float A floating point number. For fields that need to store floating point numbers.
language_code A language code. For fields that need to store language codes.
uuid A universally unique identifier (UUID). For fields that need to store UUIDs.

When to use each type

  • string: String fields should be used for simple text fields, such as IDs, labels, descriptions, and filenames. Examples include the title of a node, the name of a user, and the description of a taxonomy term.
  • integer: Integer fields should be used for numeric fields, such as node IDs, user IDs, and quantities. Examples include the node ID of a parent node, the user ID of the author of a node, and the quantity of a product in a shopping cart.
  • boolean: Boolean fields should be used for fields that can have two possible values, such as enabled/disabled, visible/hidden, and required/optional. Examples include whether a node is published, whether a taxonomy term is visible, and whether a field is required when creating a new entity.
  • text: Text fields should be used for longer text fields, such as descriptions, articles, and code snippets. Examples include the body of a node, the biography of a user, and the description of a view.
  • array: Array fields should be used for fields that can contain multiple values, such as tags, images, and files. Examples include the tags associated with a node, the images associated with a product, and the files associated with a document.
  • config_entity: Config entity fields should be used for fields that need to reference other configuration entities, such as nodes, users, and taxonomy terms. Examples include the parent node of a node, the user profile of a user, and the vocabulary associated with a taxonomy term.
  • config_object: Config object fields should be used for fields that need to reference configuration objects, such as system settings and module configuration. Examples include the system settings that control the behavior of Drupal, and the configuration of the Commerce module.
  • email: Email fields should be used for fields that need to store email addresses. Examples include the email address of a user, and the email address to which notifications should be sent.
  • url: URL fields should be used for fields that need to store URLs. Examples include the URL of a node, and the URL of an image.
  • date: Date fields should be used for fields that need to store dates and times. Examples include the created date of a node, and the date and time of an event.
  • datetime_immutable: Datetime immutable fields should be used for fields that need to store dates and times that cannot be changed, such as the created and updated dates of entities.
  • float: Float fields should be used for fields that need to store floating point numbers. Examples include the price of a product, and the weight of a shipment.
  • language_code: Language code fields should be used for fields that need to store language codes. Examples include the language code of a node, and the language code of a user