Problem/Motivation

Maybe I have totally missed it, but I can't see an option to allow the Name field in the Account Settings Manage Display to be able to fall back on the Username (or other field) if the Name field is not populated.

eg. if this module is installed after the fact and there are legacy users who do not have a Name set up (or admin accounts) and you want to view a user list in a view, using the User View mode, where you don't get a chance to add a custom views field config for empty value overrides.

Steps to reproduce

1. Set up Name as not required, or create users and then set up Name.
2. Set up a display mode that just outputs the Name field.
3. Create a view which lists Users with User View Mode with this display mode
4. You will see that it outputs a list of empty values (at least it did for me)

Proposed resolution

Add a 'fallback value' dropdown to the Name field display settings on the Display Mode config.

Remaining tasks

Tell me that this already exists and where, possibly needs documentation updates? OR
1. Create code change
2. Testing
3. RTBC

User interface changes

A dropdown in the Name field display settings on Display Mode config to choose fallback options when Name computed value is empty.

Comments

chrisdarke created an issue. See original summary.

bluegeek9’s picture

Hi @chrisdarke,

Help me understand the issue.

If the view is of a name field, and field is empty, then it should render as blank.

If the view is of the account's display name, and the name field is empty it will show the username.

chrisdarke’s picture

So if the view is of the Name field, but the module was installed AFTER a load of users were already set up, the Name column will be empty, it would be nice if there was an option to fallback to another value for the renderer of Name if the Name value is empty. As I said, its easy to do that with views fields if you are using fields but if you are rendering entities, then you would need to do something programatically, and having a fallback option in the display definition would be convenient.

bluegeek9’s picture

Hi Chris,

I think you want the user's Display name. If you are overriding the username (see field settings), the Display name will show the name field, and fallback to the username if the name field is blank.

You can use the view field if empty as you mentioned.

The name field also has an alternative name and preferred name fields. Other fields on the entity can be declared the preferred and/or alternative names. How these fields are rendered depends on which name format is used.

chrisdarke’s picture

And this is available in the User View Mode? For some reason I recall this not working with that field, I will need to build something to test that because it was a fair while ago I had access to the codebase where I needed to do this. Will let you know what I find, and see if I can replicate the issue I originally had that didn't seem to allow me to use that approach.
Cheers!

bluegeek9’s picture

I documented the process. Let me know if there is an issue. Feel free to improve the documentation.

https://www.drupal.org/docs/extending-drupal/contributed-modules/contrib...

bluegeek9’s picture

Status: Active » Fixed
//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:
  • Triage issues and adding more context to existing issues.
  • Writing documentation or patches for this project.
  • Flagging Name Field as a favorite on the project page to help others discover it and show your support.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.