Brightspot CMS Developer Guide

Tabs


The content edit form typically includes three tabs: Main, Overrides, and SEO. (Other tabs are available depending on the content type and Brightspot’s configuration.) You can add custom tabs to the content edit form.

The interface Tab specifies methods for displaying the tab, the tab’s contents, and a callback for an update event. The following sections describe how to implement these methods.

This interface is available for embedded objects displayed in the content edit form.


The following snippet illustrates how to declare a class that displays a tab in the content edit form and how to populate the tab with a label and text.

import com.psddev.cms.tool.Tab;
import com.psddev.cms.tool.ToolPageContext;

public class TimeZonesTab implements Tab { 

    @Override
    public void onUpdate(ToolPageContext page, Object content) { }

    @Override
    public String getDisplayName() { 
        return "Local Times";
    }

    @Override
    public boolean shouldDisplay(Object o) { 
        return true;
    }

    @Override
    public void writeHtml(ToolPageContext page, Object o) throws IOException { 

        Map<String, String> timeZoneIdentifiers = new HashMap<>();
        timeZoneIdentifiers.put("New York", "America/New_York");
        timeZoneIdentifiers.put("Los Angeles", "America/Los_Angeles");
        timeZoneIdentifiers.put("Mexico City", "America/Mexico_City");

        page.writeStart("table");

            page.writeStart("tr");
                page.writeStart("th");
                    page.writeHtml("City");
                page.writeEnd(); /* th */
                page.writeStart("th");
                    page.writeHtml("Time");
                page.writeEnd(); /* th */
            page.writeEnd(); /* tr */

            for (String myTimeZone : timeZoneIdentifiers.keySet()) {
                page.writeStart("tr");
                    page.writeStart("td");
                        page.writeHtml(myTimeZone);
                    page.writeEnd(); /* td */
                    page.writeStart("td");
                        String localTime = displayTime(timeZoneIdentifiers.get(myTimeZone));
                        page.writeHtml(localTime);
                    page.writeEnd(); /* td */
                page.writeEnd(); /* tr */
            }
        page.writeEnd(); /* table */
    }

    private String displayTime(String timeZoneIdentifier) {
        Calendar localTime = new GregorianCalendar(TimeZone.getTimeZone(timeZoneIdentifier));
        localTime.setTimeInMillis(localTime.getTimeInMillis());
        int hour = localTime.get(Calendar.HOUR_OF_DAY);
        int minute = localTime.get(Calendar.MINUTE);
        return (hour + ":" + minute);
    }
}
  • Declares the class TimeZonesTab as an implementation of Tab. Any class implementing this interface appears as a tab in the content edit form.
  • Specifies the tab’s label text.
  • Indicates the tab always appears in the content edit form. For an example of conditionally displaying the tab, see Conditionally displaying a tab.
  • Two methods (writeHtml and displayTime) that generate a table of localized UTC times. For an explanation of these methods, see the snippet "Implementing a custom widget in content edit page."

The following illustration shows a tab’s label and custom text.

Custom tab Custom tab



You can use the method Tab#shouldDisplay to show or hide a custom tab based on the passed object or any other object you can access.

@Override
public boolean shouldDisplay(Object content) {
    return (content instanceof Article); 
}
  • Tests if the current object is of type Article; if so, Brightspot displays the custom tab.



Every change in the content edit form (even before clicking Publish) calls the method Tab#onUpdate. You can use this method to dynamically update the database without requiring the user to click Publish.

@Override
public void onUpdate(ToolPageContext page, Object content) { 
    State state = State.getInstance(content); 
    updateFields(page, state); 
}
  • Traps updates to the content edit form and receives an object representing the current page and another object representing the content.
  • Instantiates a State object corresponding to the current object.
  • Passes the content and state objects to a private method (not shown) that updates the database.

Previous Topic
Content edit widgets
Next Topic
Profile tabs
Was this topic helpful?
Thanks for your feedback.
Our robust, flexible Design System provides hundreds of pre-built components you can use to build the presentation layer of your dreams.

Asset types
Module types
Page types
Brightspot is packaged with content types that get you up and running in a matter of days, including assets, modules and landing pages.

Content types
Modules
Landing pages
Everything you need to know when creating, managing, and administering content within Brightspot CMS.

Dashboards
Publishing
Workflows
Admin configurations
A guide for installing, supporting, extending, modifying and administering code on the Brightspot platform.

Field types
Content modeling
Rich-text elements
Images
A guide to configuring Brightspot's library of integrations, including pre-built options and developer-configured extensions.

Google Analytics
Shopify
Apple News