Chapter 23. Object viewers

Object view would be of limited utility without the ability to actually view an object on the page. Object viewers enable this. CONTENTdm® is capable of storing any file type, and dmBridge should therefore ideally be able to display as many different file types (images, audio, text, video...) as possible.

Every object viewer in dmBridge is its own class, in its own file on disk. A number of object viewers are provided (in the dm/system/template/viewers folder) that are capable of handling many common file types.

Object viewers are assigned on a per-collection basis. Which viewer is used for which file type depends on the associations defined in the Collections section of the Control Panel. Here, you can associate a particular object viewer class with a particular media (MIME) type.

Every object viewer class must implement the DMObjectViewerDelegate interface. This requires writing three methods:

getName()

Should return the name of the viewer.

getHTMLTag()

Should return an HTML fragment that will render the viewer.

getHTMLTagNoJS()

Should return an HTML fragment that will render the viewer without any required or optional JavaScript. This should be written even if the viewer will not work without JavaScript; clients will assume the responsibility of including the necessary script(s) themselves.

If an object viewer requires JavaScript or CSS, it must additionally implement a fourth method, viewerWillRender().

See dm/system/template/viewers/DMGenericImageViewer/DMGenericImageViewer.php for an example of how an object viewer works.

Adding your own custom object viewer is as simple as writing your own class in the pattern of the existing ones and defining the associations in the Collections section of the Control Panel.

Custom viewers must be saved in the dm/extensions/viewers folder. The class name of the viewer must match the filename, and the class file must be saved in a folder with the same name as the class. For example:

dm/extensions/viewers/
    MyCustomViewer/
        MyCustomViewer.php
			

MyCustomViewer.php, then, would contain a class named MyCustomViewer.