GlobalFieldReference
GlobalFieldReference
GlobalFieldReference describes a field with data_type set to global_field, which places a global field inside a content type schema or inside another global field. It adds the UID of the global field and the non-localizable flag to the properties of Field.
When to Use This Class: Use this class to reuse a set of fields, for example an SEO global field in every page content type. It also nests one global field inside another.
Conceptual Role: Acts as the Field subclass that the SDK creates for a field with data_type set to global_field.
Returns: GlobalFieldReference. A global field reference of a schema.
Properties
GlobalFieldReference inherits every property of Field, and adds or replaces the properties below.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| ReferenceTo | string? | No | null | UID of the global field this field uses. Serialized as reference_to. |
| Multiple | bool | No | false | Lets the field hold more than one value. Replaces Field.Multiple. Serialized as multiple. |
| Mandatory | bool | No | false | Requires a value in every entry. Replaces Field.Mandatory. Serialized as mandatory. |
| Unique | bool | No | false | Requires a unique value. Replaces Field.Unique. Serialized as unique. |
| NonLocalizable | bool | No | false | Keeps the value the same in every locale. Serialized as non_localizable. |
Class-Level Notes
Replaced properties.
- GlobalFieldReference declares its own Multiple, Mandatory, and Unique, which hide the Field properties of the same name. The SDK sends the values of the GlobalFieldReference properties.
- Set and read these properties through a variable of type GlobalFieldReference. A value set through a variable of type Field does not reach the request.
- The SDK always sends non_localizable, with false when you leave it unset.
Nested global fields.
- To nest a global field inside another, add a GlobalFieldReference to the Schema of the outer global field. The Create a global field request of the Content Management API reference shows the nested schema.
Method Index
GlobalFieldReference has no methods. Set its properties and add it to ContentModelling.Schema.
Class-Level Snippet
The snippet below creates a content type that uses an existing seo global field.
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;
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 GlobalFieldReference { DisplayName = "SEO", Uid = "seo", DataType = "global_field", ReferenceTo = "seo" }
}
};
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}");
}