ExtensionField
ExtensionField
ExtensionField describes a custom field in a content type or global field schema: a field that an extension renders in the entry editor. It adds the extension UID and the field configuration to the properties of Field.
When to Use This Class: Use this class to add a custom field that you uploaded or created with the Extension class, for example a color picker.
Conceptual Role: Acts as the Field subclass that the SDK creates for any field that has an extension_uid. The SDK also creates it for a field with data_type set to extension.
Returns: ExtensionField. A custom field of a schema.
Properties
ExtensionField inherits every property of Field and adds the properties below.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| extension_uid | string? | No | null | UID of the custom field extension. Serialized as extension_uid. |
| config | Dictionary<string, JsonElement>? | No | null | Configuration values the extension reads. Serialized as config. |
Class-Level Notes
Field settings.
- The property names extension_uid and config are lowercase in the SDK.
- Set DataType to the data type of the custom field, for example text or number. The SDK reads any field with an extension_uid as ExtensionField, so the data type does not change the class.
- The Create Content Type with Extension Field request of the Content Management API reference describes the request.
Method Index
ExtensionField has no methods. Set its properties and add it to ContentModelling.Schema.
Class-Level Snippet
The snippet below creates a content type with a custom color field that an existing extension renders.
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Fields;
using System.Text.Json;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ContentModelling model = new ContentModelling
{
Title = "Blog Post",
Uid = "blog_post",
Schema = new List<Field>
{
new TextboxField { DisplayName = "Title", Uid = "title", DataType = "text", Mandatory = true, Unique = true },
new ExtensionField
{
DisplayName = "Theme Color",
Uid = "theme_color",
DataType = "text",
extension_uid = "<EXTENSION_UID>",
config = new Dictionary<string, JsonElement> { ["default_color"] = JsonSerializer.SerializeToElement("#6c5ce7") }
}
}
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ContentType().Create(model);
Console.WriteLine(response.OpenJsonObjectResponse()["notice"]);
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}