Support and Documentation

Rich-text toolbar

To deploy a rich-text toolbar, you define it as a class and then assign the class to a field.

Defining a toolbar class

You can deploy customized rich-text editors that have certain controls for marking up text. For example, the following class provides only the boldface, italics, underline, and hyperlink buttons.

package content.article;

import java.util.Arrays;
import java.util.List;

import com.psddev.cms.rte.RichTextToolbar;
import com.psddev.cms.rte.RichTextToolbarItem;
import com.psddev.cms.rte.RichTextToolbarStyle;

public class CustomRichTextToolbar implements RichTextToolbar {

    @Override
    public List<RichTextToolbarItem> getItems() {
        return Arrays.asList(
            RichTextToolbarStyle.BOLD,
            RichTextToolbarStyle.ITALIC,
            RichTextToolbarStyle.UNDERLINE);
    }
}

In the previous snippet—

  • Line 10 specifies a class that implements RichTextToolbar.

  • Lines 15–17 specify the controls appearing in the toolbar.

Associating a toolbar class with a rich-text field

You associate a customized rich-text editor with a text field using the @ToolUi.RichText annotation.

package content.article;

import com.psddev.cms.db.Content;
import com.psddev.cms.db.ToolUi;

public class Article extends Content  {

    @ToolUi.RichText(toolbar=CustomRichTextToolbar.class)
    private String body;

}

In the previous snippet, line 8 applies the toolbar class created in Defining a toolbar class to the rich-text field body.

custom-rte.png

The following classes have controls which can be used in your customized rich-text toolbar's getItems method: