How to modify the user profile icon from top menu right?

Last modified by Clemens Robbenhaar on 2020/11/17

The User Profile Icon from the top menu right is an UIX Extension Point:

UserProfileIconBefore.png

First you need to understand what is an extension point. Here are more details about Extension points: Extension Point Tutorial.
Here is the list of extension points available in XWiki: Available Extension Points.

In this case you want to modify: TopMenuRight extension point. It can be found in the wiki in the page XWiki.UserProfileUIX.

For example you can replace the image with the user's name.

  • Go to the page: XWiki.UserProfileUIX .
  • Edit the page in Object mode
  • The page holds an object type of "XWiki.UIExtensionClass", go to Executed Content 
  • Then comment the line:
    #mediumUserAvatar($xcontext.user)

    Since this is a customization that will bring  some complexity in the case of an upgrade, it a good practice to add a comment before it, so you track the details about it.

    ## Customization remove the avatar and display user's name in the top menu right.
    ## #mediumUserAvatar($xcontext.user)
  • Then you have to get the user's name from it's profile. This way the user can be get from it's profile:
    ##First you need to resolve the user as a document:
    #set ($userDoc = $xwiki.getDocument($xcontext.user))
    ##Then you need to get the user object form the user document:
    #set ($userObj = $userDoc.getObject('XWiki.XWikiUsers'))
    ## In the end you can access all the properties with:
    #set ($firstName =  $userObj.getValue('first_name'))
    ## Display the name
    $firstName
  • Save the page and enjoy the results.

    UserProfileIconAfter.png

However if you want to remove the extension point here is how you can do it: Disable extension points.

Tags:
   

Get Connected