Here are the steps which I followed:

  1. Added the user referenced field in the content type so one author can add multiple users who contributed in that content.
  2. Using views i am showing the content and showing the users who contributed in this node.

My issue is that the view is showing the usernames of all the users. I want to convert those usernames to the Display name.


As with most problems this one too can be solved in more than one way.

Probably the easiest, common, and "most Drupal" way is through using View modes.

View modes

View modes are different ways of displaying entity content, depending on the context. Don't confuse them with Views module that is used for building lists of entities, they are completely different things.

An example of a View mode: you want the user profile page to show all user user fields, but in a lot of other places on the site you need the username and their geo-location, so you keep the Default User View mode for profiles, and create a new View mode where you only enable the username and geofield. Then activate the new user view mode in all places where you need to show the user with their geo-info.

In your case you have a User Reference field in Content Views and you want to change how the user info from that field is presented:

  1. Create a new User View mode under People Manage display (/admin/config/people/accounts/display) > Custom display settings
  2. Enable the newly created View mode. After you enable it and Save the page will reaload and a new Drupal tab will appear named after your new View mode.
  3. Visit the page of the newly created View mode (click on that tab) and adjust which user fields you want to show under that View. In your case that might be firstName and lastName, disable all others by dragging them down to the Disabled list (and Save).
  4. Edit your Content Views (this is now the list of content you mention in your question, not the View modes), edit the User reference field and change the View mode option to the one you created in step 1.

UserReference View mode in Views

Now your User reference field will show only the user fields you have enabled in the View mode on People account configuration.

You can use this View mode in other places too where you want any User data to display only as the Display names.

Through Views

Alternatively, you can achieve the same result with Contextual filters within a Views Block Display to show only users referenced by the article you're currently viewing, and only showing that Block on the pages of that specific Content Type.

| improve this answer | |
  • Thanks for the detailed answer. I followed your steps but i could not understand step 4. Can you please describe more? – Saqib Riaz Jun 4 at 21:36
  • I added a screenshot to clarify. In step 4 you go to your views where you're building your list of content. One of the fields there is the User reference field, as you mention in your question. Edit that field settings as you see in the screenshot, change the View mode dropdown from Default to your new one (RealName in the screenshot). – prkos Jun 4 at 21:46
  • Thanks for adding screenshoot. I could not understand what is formatter in your screenshoot? – Saqib Riaz Jun 5 at 17:00
  • Bricks is a module I use on the site where I took the screenshot, it isn't relevant to your case, you don't need Bricks. Set the Formatter to Default or which ever option suits you best, as long as it allows for Views mode to be chosen. I think the Formatter might depend on what you have set for that field under its settings. – prkos Jun 5 at 18:39
  • When i select the " Rendered Entity" Formatter in Views field settings then "People" view mode show up in the drop down. And this only visible to the logged in users. Can we make this visible for all users? – Saqib Riaz Jun 5 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.