createWidgetClass(options)

Creates a CMS widget type without adding it to the registry of CMS widget types.

Copy
const TextWidget = Scrivito.createWidgetClass({
  attributes: {
    text: 'html',
  },
  
  onlyInside: 'BlogArticlePage',
});

Scrivito.createWidgetClass does not automatically add the generated class to the registry of CMS types. Instead, it is considered an „abstract class“. An abstract class is useful:

  • as a superclass for specialized CMS widget types,
  • for overloading an API method before registering the final type using Scrivito.provideWidgetClass.

Options

  • attributes (Object) – The attribute definitions of the widget class. See Scrivito.createObjClass for details.
  • extend (WidgetClass) – The widget class from which this one should inherit its attributes. By default, the Widget base class is used.
  • onlyInside (String or Array) – 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 class than the ones specified here.

Example

Create a an abstract class named BaseClass and an ImageWidget subclass.

Copy
const BaseClass = Scrivito.createWidgetClass({
  attributes: {
    blob: 'binary',
  },
});

class ImageWidget extends BaseClass {
  myMethod() {
    return 'cool';
  }
}

Scrivito.provideWidgetClass('ImageWidget', ImageWidget);