Hiding

By default, Brightspot displays the following standard widgets in the Content Edit Page: References, Revisions, SEO, Sites, Template, and URLs. Some of these widgets appear depending on an item’s state. For example, the Revisions widget appears only after you save a draft, change a workflow state, or publish an item. In addition, Brightspot automatically displays any custom widgets created for the content edit page. (For information about creating custom widgets for the content edit page, see Creating and Creating Updating Content Edit Widgets.)

You can hide widgets at the content-type level and at the custom widget level.

Hiding Widgets at the Content-Type Level

You can hide the standard or custom widgets at the content-type level. For example, you can show the URLs widget on content edit pages for articles, and hide the widget on content edit pages for images.

The interface ContentEditWidgetDisplay contains a method shouldDisplayContentEditWidget that you can override to specify if a widget is visible or not in a content edit page. You implement the interface at the Model level, which gives you the flexibility for showing or hiding widgets depending on content type. The following example shows how to hide the standard URLs widget in an article’s content edit page.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package content.article;

import com.psddev.cms.db.Content;
import com.psddev.cms.db.ToolUi;
import com.psddev.cms.tool.ContentEditWidgetDisplay;
import com.psddev.cms.tool.content.UrlsWidget;
import com.psddev.dari.db.Recordable;

public class Article extends Content implements ContentEditWidgetDisplay {

    @Recordable.Required
    private String headline;

    @ToolUi.RichText
    private String body;

    /* Getters and Setters */

    @Override
    public boolean shouldDisplayContentEditWidget(String widgetName) {
        if (widgetName.equals(UrlsWidget.class.getName())) {
            return false;
        } else {
            return true;
        }
    }
}

In the previous snippet, lines 19–25 implement the method shouldDisplayContentEditWidget. Brightspot calls this method for each widget eligible to appear in the content edit page. If the widget’s name is the same as the URLs widget’s name, the method returns false and the widget does not appear. See the following illustration.

../../../_images/no-urls-widget-content-edit-page.png

See also:

Hiding Custom Widgets

If you create a custom widget, you can hide it from the Content Edit Page—regardless of the content type—by overriding the shouldDisplay method in the widget’s definition.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package widgets;

import com.psddev.cms.tool.ContentEditWidget;
import com.psddev.cms.tool.ContentEditWidgetPlacement;
import com.psddev.cms.tool.ToolPageContext;

import java.io.IOException;

public class CurrentTimesWidget extends ContentEditWidget {

    @Override
    public void display(ToolPageContext page, Object content, ContentEditWidgetPlacement placement) throws IOException {

        page.writeStart("p");
            page.writeHtml("My widget for personal notes.");
        page.writeEnd(); /* p */
    }

    public ContentEditWidgetPlacement getPlacement(ToolPageContext page, Object content) {
        return ContentEditWidgetPlacement.BOTTOM;
    }

    public String getHeading(ToolPageContext page, Object content) {
        return "My Custom Widget";
    }

    @Override
    public boolean shouldDisplay(ToolPageContext page, Object content) {
        return false;
    }
}

In the previous snippet—

  • Lines 11–25 define a custom widget that appears under the content edit form.
  • Lines 27–30 hide the custom widget from the content edit page. See the following examples.
Custom widget shown Custom widget hidden
../../../_images/custom-widget-shown.png ../../../_images/custom-widget-hidden.png

See also: