Test Enterprise-Class Web CMS Scrivito Free for 30 Days
Test Scrivito Free for 30 Days
New in 1.20.0

configureObjClassForContentType(mapping)

Defines which CMS object class to use if content is uploaded.

Scrivito.configureObjClassForContentType({
  'image/*': 'Image',   // Factory default
  'video/*': 'Video',
  '*/*': 'Download',    // Factory default
})

Provides a mapping that consists of key-value pairs where each pair is made up of a file type pattern as the key and a CMS object class name as the value. When looking up the CMS object class to use for the uploaded data, the most specific match will be used.

If no mapping is configured, a default is used instead.

Params

  • mapping (Object) – A mapping from the file type pattern to a CMS object class name. A file type pattern may include either a single wildcard for the subtype part (e.g. image/*), or be the fallback pattern, */*.

Throws

  • ArgumentError if he mapping is erroneous.
  • ScrivitoError if the mapping is configured more than once.

Remarks

This configuration can be defined only once.

The mapping must include an entry for the fallback pattern */*.
The file type pattern does not support prefix matches such as audio/mp*.

Examples

Define specific CMS object classes for audio files:

Scrivito.configureObjClassForContentType({
  'audio/mp3': 'MyMp3',    // Default for all MP3s
  'audio/*': 'MyAudio',    // Default for all other audio files
  'image/*': 'Image',      // Factory default
  '*/*': 'Download',       // Factory default
});

Override factory defaults:

Scrivito.configureObjClassForContentType({
  'image/*': 'BetterImage', // Override factory default for image files
  'image/png': 'PngImage',  // Register default for PNG images
  '*/*': 'Octetstream'      // Override factory default for all other files
});