Search the documentation
 Show GitHub edit links  Hide GitHub edit links
In OpenCms since: 9.5 Documented since: 9.5 Latest revision for: 9.5 Valid for OpenCms: 10.5.2

OpenCms allows hiding of elements in the content editor for users of specific groups. Which element is hidden for which group is specified in the content type definition. If the default options for hiding or showing an element are not sufficient for you, you can also write your own class that defines when to hide or show a content element.

Defining the visibility of a schema element

Which schema element should be visible to which users is defined in the schema definition (XSD) in the section xsd:annotation/xsd:appinfo. Using the <visibility> node, you can define when a content element should be shown in the content editor. A possible configuration could look like:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

    <xsd:include schemaLocation="opencms://opencms-xmlcontent.xsd"/>

    <xsd:element name="HideExamples" type="OpenCmsHideExamples"/>

    <xsd:complexType name="OpenCmsHideExamples">
        <xsd:sequence>
            <xsd:element name="HideExample" type="OpenCmsHideExample" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="OpenCmsHideExample">
        <xsd:sequence>
            <xsd:element name="NotForEveryOne" type="OpenCmsString" />
            <xsd:element name="ForEveryOne" type="OpenCmsHtml" />
        </xsd:sequence>
        <xsd:attribute name="language" type="OpenCmsLocale" use="required"/>
    </xsd:complexType>

    <xsd:annotation>
        <xsd:appinfo>
            <visibilities>
                <visibility element="Title" params="Administrators|Projectmanagers|ROLE.GALLERY_EDITOR" />
            </visibilities>
        </xsd:appinfo>
    </xsd:annotation>

</xsd:schema>

Nested in the node xsd:schema/xsd:annotation/xsd:appinfo/visibilities we provide a node <visibility element="NotForEveryOne" params="Administrators|Projectmanagers|ROLE.GALLERY_EDITOR">. It says that the element named NotForEveryOne is only visible for members of one of the groups provided in the attribute params, and for users that have at least one of the listed roles.

The attribute params configures the visibility handler. The default handler takes a pipe (|)-separated list of group names and role identifiers. For users that are members of at least one of the listed groups (or that have at least one of the listed roles), the content element is displayed in the editor. For all other users it is hidden. Consequently, if you leave the list empty, the element is never displayed.

The <visibility> node takes a third, optional, argument class. If you want to replace the default visibility handler, provide the qualified class name of handler you want to use. Note that a non-default handler will usually accept different params values than the default handler.

Defining your own visibility handler

To implement your own visibility handler, you have to implement the interface I_CmsXmlContentVisibilityHandler found in the package org.opencms.xml.content. The only method to implement is isValueVisible(..). The method return a Boolean value, indicating if the element should be shown or not. The method's arguments provide various contextual information to decide about the visibility. Additionally a configuration string is provided and you are completely free about how to parse and use it.

To use the self-defined handler, provide its qualified name as the class attribute in the <visibility> node.

You can improve this page

Please contribute your suggestions or comments regarding this topic on our wiki. For support questions, please use the OpenCms mailing list or go for professional support.