getSchema
The getSchema method is responsible for returning models and locales in the visual editor format.
The getSchema
method should fetch the content models from the underlying content source and convert them to an array of visual editor models. If the underlying content source supports locales, this method may also fetch the available locales and convert them to an array of visual editor locales.
You can extend the Schema
type with custom data using the SchemaContext
generic type and store it in the schema's context
property. The visual editor will cache this data along with the rest of the Schema
. You can retrieve the cached schema using the cache.getSchema
method, which is passed to the init
method.
Return Value
The getSchema
method should return a Promise
that resolves with a Schema
object containing the following properties:
model
: an array of visual editor models represented by theModel[]
type.locales
(optional): an array of visual editor locales represented by theLocale[]
type, if the underlying content source supports locales.context
: a custom object as defined by theSchemaContext
generic type. This object can store additional data and will be cached by the visual editor along with the Schema.
Example
Continuing with the example
for the init method, you can use the apiClient to fetch the content source models and locales, convert them to visual editor models, and then return them as a Schema object.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
The convertToStackbitModels
and convertToStackbitLocales
are examples of utility methods that receive arrays of content source models and locales and convert them to visual editor models and locales