Studio Developer Manual / Version 2310
Table Of Contents
With a content initializer you can initialize the properties of a newly created content item. A
content initializer will be called while a new content object is being created by the
NewContentAction
. Only one initializer can be defined for each content type. You
must register custom initializers with the global
@coremedia/studio-client.main.editor-components/sdk/editorContext
.
Simply call the registerContentInitializer(contentTypeName, initializer)
method.
The following code defines a simple initializer that sets the content's language property to German by default:
import StudioPlugin from "@coremedia/studio-client.main.editor-components/configuration/StudioPlugin"; import IEditorContext from "@coremedia/studio-client.main.editor-components/sdk/IEditorContext"; import ContentInitializer from "@coremedia-blueprint/studio-client.main.blueprint-forms/util/ContentInitializer"; import Content from "@coremedia/studio-client.cap-rest-client/content/Content"; class MyStudioPlugin extends StudioPlugin{ //... init(editorContext: IEditorContext): void { editorContext.registerContentInitializer("CMTeaser", MyStudioPlugin.initLanguage); } static initLanguage(content:Content):void { ContentInitializer.setProperty(content, "locale", "de"); } }
Example 9.28. Defining a content initializer
Client-side initialization might be sufficient for simple initialization scenarios. If you have complex requirements, consider using server-side initialization: Refer to Section 9.21.2, “Intercepting Write Requests” for details.