provideObjClass(name, objClassOrDefinition)

Creates a page or resource type for the CMS, or registers an already existing class.

If a class is given, this function registers an unnamed CMS object class under the given name. Otherwise, Scrivito.provideObjClass generates an object class using the given definition.

Object classes serve as boilerplates for CMS objects. Their main purpose is to define the attributes the instances require, for example a string attribute named “title”, or a binary attribute for binary data like an image or a PDF document.

Params

  • name (String) – The name of the CMS object class.
  • objClassOrDefinition (Class, Object) – Definition for generating an object class (see below) or an already generated class that Scrivito should register.

objClassOrDefinition (Object)

  • attributes(Object) – The definition of the attributes of the CMS object class. Either only the type, or an array consisting of the type as the first element, and a configuration object as the second element.
    • For enum and multienum attributes, the configuration object is mandatory and must contain a values key (Array), the list of the values that can be assigned to the attribute.
    • For widgetlist, reference and referencelist attributes, the configuration object is optional and can be used to provide the only key (String or Array).
      • With widgetlist attributes, the value of only can be the name of a widget class (String) or a list of such names (Array). If specified, only widgets of the given class or classes can be placed into the widgetlist attribute.
      • With reference and referencelist attributes, the value of only can be the name of an object class (String) or a list of such names (Array). If specified, only CMS objects of the given class or classes can be placed into the attribute.
  • extractTextAttributes (Array of String) – The names and order of the attributes to be used by Scrivito.extractText. Default: []. The following attribute types are supported:
    • string
    • html
    • widgetlist
    • 'blob:text' (the text metadata item of a binary Obj’s blob attribute)
  • extend (ObjClass) – The CMS object class from which this one should inherit its attributes. The specified class must inherit from Obj. By default, the base class Obj is used.

  • onlyChildren (String or Array of String) – A single page class name (string) or a list of class names (array). Only instances of the page classes specified in this option can be added as subpages to pages of this class. An empty array as the value will be ignored. Specifying this option for a binary object class causes an error.

  • onlyInside (String or Array of String) – A single page class name (string) or a list of class names (array). Pages of this class must have a page of (one of) the class(es) specified here as their parent. So, pages of this class can only be added as subpages to pages of (one of) the class(es) specified here. An empty array as the value will be ignored. Specifying this option for a binary object class causes an error.

  • onlyAsRoot (Boolean) – [New in 1.24.0]If set to true, pages of this object class represent a site and serve as a homepage, and are therefore not available as subpages. Applicable only if the multi-site feature is enabled for the Scrivito CMS concerned. Specifying this option for a binary object class causes an error.

  • validAsRoot (Boolean) – [New in 1.24.0]If set to true, pages of this object class can be used both as homepages and subpages. Applicable only if the multi-site feature is enabled for the Scrivito CMS. Specifying this option for a binaryobject class causes an error.


    If no object class has either validAsRoot or onlyAsRoot set to true, homepages can be of any object class for pages.

Returns

ObjClass

Remarks

User-defined page models inherit all methods from Obj.

See also

provideWidgetClass – The definition of pages and widgets is fairly identical. It only differs with respect to the base type: Obj vs. Widget.

Examples

Create a SamplePage class, showing off with attribute types:

Create an OpaqueImage resource, exemplifying the remaining attribute types:

Create a Homepage class with a title, a childOrder, a topBody and a bottomBody attribute. childOrder enables editors to sort the subpages of Homepages; topBody and bottomBody are used by Scrivito.extractText:

Create a Download class whose text metadata item is used by Scrivito.extractText:

Create an abstract BaseClass and its NewsPage subclass: