You can use the Custom Wizard Plugin to manage Discourse’s custom fields. The primary use case for this feature is managing custom fields for topics, posts, categories and groups created in wizard actions, but you could use it to manage custom fields for any purpose in Discourse.
https://www.loom.com/share/5175c4fa58b9461abad3e3eabe16d787
What are “Custom Fields”?
In Discourse a “custom field” is a data store associated with a standard Discourse data model. For each of the Discourse data models there is an associated “custom_fields” table in the database where you can store data associated with a particular “row” (e.g. a particular topic or post) in the standard table. The custom field data is stored according to the “type” that is set for it.
Discourse models with custom fields
- Users
- Topics
- Posts
- Categories
- Groups
Custom field types
- String
- Boolean
- Integer
- JSON
Custom Field Management
You can manage custom fields for all Discourse models, aside from user custom fields (see below), in the Custom Wizard Custom Field Admin UI.
All inputs you see above are required to register a field. We’ll go through each in turn
Class
This is the Discourse model you want to associate your custom field with (see above)
Type
This is the data type of the field (see above)
Name
This is the name of your custom field. For computational purposes it will be transformed to a lowercase underscore separated string, for example “Peanut Butter” will become “peanut_butter”.
Serializers
By default, any custom field you add to a Discourse model won’t be sent from the server to the client. Each custom field has to be explicitly “serialized” to the client in each context it is needed. The list of available serializers will change depending on what class you select.
The serializer names related to the names of the serializers in the code:
-
Topic View
: This is the data sent when you’re looking at a topic -
Topic List Item
: This is the data sent with each list item on any topic list in Discourse. -
Post
: The data sent for every post -
Category
: This translates to the “BasicCategorySerializer” in the code.
User Custom Fields
You can manage user custom fields in the Customize > User Fields Admin UI. Any user fields you register there can be used in a Custom Wizard.
Custom Fields in Wizard Actions
You can add custom fields to any Topic, Post, Group or Category you create in a wizard action. For each relevant action you’ll see a “Custom” entry in the Actions section.
In the “map” entry for the custom field map you can change the selection type to “custom field” and you will see a list of the custom fields you have registered in the Custom Wizard’s Custom Field Admin UI.