provideWidgetClass(name, widgetClassOrDefinition)

Creates a widget class or registers an already existing class.

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

Widget classes serve as boilerplates for CMS widgets. Their main purpose is to define the attributes the instances require, for example an html attribute named “content” and a string attribute named “summary”.

Params

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

widgetClassOrDefinition (Object)

  • attributes(Object) – The definition of the attributes of the CMS widget 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
  • extend (WidgetClass) – The CMS widget class from which this one should inherit its attributes. The specified class must inherit from Widget. By default, the base class Widget is used.

  • onlyInside (String or Array of String) – Optionally, a single page or widget class name (String) or several such names (Array) specifying the class(es) in whose instances widgets of this class must be contained. So, instances of this widget class cannot be placed on pages or into widgets of any other classes than the ones specified here.

Examples

Create an advanced image widget class with support for some fancy features:

Create a TextWidget widget whose text attribute is used by Scrivito.extractText:

Create a FactWidget widget whose key and value attributes are used by Scrivito.extractText:

Create an abstract BaseClass and a subclass of it named AdvancedImageWidget: