Skip to content

Latest commit

 

History

History
90 lines (63 loc) · 2.79 KB

user-context-menu.adoc

File metadata and controls

90 lines (63 loc) · 2.79 KB

User context menu

The user context menu usually contains the menu items specific to the logged on user. In the default layout it is the rightmost menu item in the top navigation and it contains only a Logout link.

The default user context menu expanded.

Adding menu items

The user context menu can be customized by intercepting the AdminMenuEvent and customizing the UserContextAdminMenuGroup.MENU_PATH group (/user-context).

Adding a custom link to the user context menu
@EventListener
public void buildUserContextMenu( AdminMenuEvent menu ) {
    menu.item( UserContextAdminMenuGroup.MENU_PATH + "/profile" )
        .title( "Your profile" )
        .url( "@adminWeb:/my/controller" );
}

See the documentation on customizing the nav sections for more information.

Setting a display name and avatar

The user context menu by default shows a user icon followed by the name of the current principal. A custom display name and optional thumbnail url can be set by intercepting the custom UserContextAdminMenuGroup event.

A thumbnail will be rendered as an avatar for the logged on user.

UserContextAdminMenuGroup has the following properties:

Property Description Default value

displayName

The text to show on the menu item. If the name is empty, no text will be rendered.

current principal name

thumbnailUrl

The image to show on the menu item. If the url is empty, a user icon is rendered instead.

none

Example manually setting a display name and avatar
@EventListener
public void registerDefaultUserContextAdminMenuItem( UserContextAdminMenuGroup userContextAdminMenuGroup ) {
    // the original event is prefilled with the current principal name
    if ( "admin".equals( userContextAdminMenuGroup.getDisplayName() ) ) {
        userContextAdminMenuGroup.setDisplayName( "Administrator" );
        userContextAdminMenuGroup.setThumbnailUrl( "http://www.gravatar.com/avatar/73543542128f5a067ffc34305eefe48a" );
    }
}

The configured UserContextAdminMenuGroup is also added to the resulting Menu item under the UserContextAdminMenuGroup.ATTRIBUTE attribute.

Note
Other modules, for example UserModule, automatically integrate with Admin web to set display names and avatar.

CSS styling

The default user context menu adds the following CSS classes:

CSS class

Description

admin-nav-user-context

Added to the main menu item (li element).

with-thumbnail

Added to the main menu item (li element), if a thumbnailUrl was set (and an avatar is rendered).

admin-nav-user-context-thumbnail

Added to img element of the avatar.