strapi/docs/docs/custom-fields.md
2022-11-10 12:10:20 +01:00

3.4 KiB
Raw Blame History

title slug tags
Custom fields /custom-fields
content-type-builder
plugins

Custom fields

Summary

Custom fields provide a way to replace the inputs of existing Strapi types to improve the content editing experience.

Detailed design

A custom field needs to be registered in both the admin and server.

Server

To register a custom field on the server, see documentation.

The custom field will be added to Strapi during the server register lifecycle.

The type: customField saved on the schema.json for a content-type or component is converted to the underlying Strapi data type by calling the convertCustomFieldType function as soon as the app starts during the register lifecycle, right after all custom fields have been loaded.

Admin

To register a custom field to the admin panel, see documentation.

A custom field being saved on a content-type or component will have its underlying data type converted from the underlying data type to type: customField just before save in the formatAttributes function of the cleanData util

Packaging

A custom field can be registered in either a Strapi application or Strapi plugin. However, they can only be shared through plugins by publishing the package on npm.

Example

Tradeoffs

  • We do not yet offer the ability to create a custom database type in Strapi.
  • When extending a custom fields base and advanced forms in the Content-type Builder, it is not yet possible to import custom input components.
  • We do not allow custom fields to use the relation, component, dynamic zone and media types.

Alternatives

We consider making special packages for Custom fields but :

  • Custom fields would not have been able to access other features from the plugin API. While that is not always required, it also enables custom fields that do need it to implement more advanced behaviors. For example, a custom field can also use injection zones if needed.
  • Introducing a new custom field type of package would have required a new loader in Strapi, and a new section and review processes on the marketplace, which would have made the feature more complex to ship.
  • The overkill aspect of the plugin API for a simple custom field could be mitigated by adding a new plugin generator that only created the files required for a custom field.

Resources