I defined a View which displays the list if users. Check the View definition -> in Fields section -> "User: Name" field -> Configure field: User: Name -> More.
There is an option called "Use formatted username. If checked, the username will be formatted by the system. If unchecked, it will be displayed raw."
Whether this option is checked or unchecked, the user name is always truncated. It looks like a bug.
By the way, when I debug the theme_username($variables) function during the view display, there are two values: $variables['name'] and $variables['name_raw'] and the perhaps Views is using the "name" in both cases, instead of "name_raw" for raw display (because "name" is indeed truncated, and "name_raw" is full length).
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | views-link-raw-user-name-1445404-22.patch | 1.52 KB | ronino |
| #16 | interdiff-15-16.txt | 579 bytes | cboyden |
| #16 | views-link-raw-user-name-1445404-16.patch | 1.56 KB | cboyden |
| #16 | views-raw-link-encoding.png | 41.33 KB | cboyden |
| #15 | views-link-raw-user-name-1445404-15.patch | 1.54 KB | jgullstr |
Comments
Comment #1
dawehnerWell views doesn't truncate something, though maybe some kind of custom theme_username does this.
name_raw is generated by template_preprocess_username, that's something views doesn't have to care about/changes.
'name' is loaded directly from the database so i think views can't do something wrong here. Can you please show an export of your view? Maybe you have configured views to truncate the username.
You have to know that the link-to-user overrides the format-username checkbox.
Here is a small patch, which updates the documentation and makes the code a bit easier to read.
Comment #2
raincloud commentedPlease find attached my view.
I thought that the idea behind the option "Display formatted" was whether to display the user name not truncated (from "name_raw") or truncated (from "name").
In the current state, if I need to display non-truncated username in one view and truncated in another view, it is not possible. (or maybe I don't know yet how)
However, it would be possible, if the code in views/modules/user/views_handler_field_user_name.inc looked like this: adding an additional parameter for theme(username) in the last line - not sure if it's legal to do like this, but I checked and in my view it works ok
Now it is possible for me to actually make use of this setting from Views UI ("Display formatted") in mytheme_username like this in the first "if" statement:
Comment #3
raincloud commentedI tried also something else. Instead of hacking and passing additional argument to theme(username), I set the username to always display the name_raw in my theme(username) function and used a truncation option directly in View definition: Configure field: User: Name -> Style settings -> Trim this field to a maximum length - but then the field disappeared completely from view. Looks like a linked field cannot be truncated, because when unchecked the "Link this field to its user" then the field appears ok (and truncated). But user name must be linked.
Comment #4
tim.plunkettTriggering the testbot.
Comment #6
Morten Najbjerg commentedA quick fix for this is to add user uid as a field and hide it.
Then uncheck the "Link this field to its user" and create the link manually using user/[uid].
But yes - it seems to be a bug that the username is not displayed as raw when "Link this field to its user" is checked
Comment #7
dadaisme commentedAnd the bug is still there.
I'll use the quick fix...
thx.
Comment #8
JvE commentedThere are all kinds of things going on with the user name filed and the options 'link_to_user', 'overwrite_anonymous' and 'format_username'.
This bug appears to be for the case where 'link_to_user' is TRUE and 'format_username' is FALSE.
The expectation is that a link is created to the user profile, showing the raw username. Like
<a href="/user/1">$raw_name</a>Is this correct?
See #1609088: Undefined index: uid in views_handler_field->get_value() (line 375 of views_handler_field.inc) for more information on this functionality and the problems surrounding it.
Comment #9
mmilano commentedHere is a workaround to bypass the "link this field to its user" feature that is causing the issue:
- Add a uid field to the view and exclude it from display
- Re-order, and make sure the uid field is above the name field (so it picks up for replacement values)
- Edit the user name field
- - Uncheck "Link this field to its user"
- - Check "Rewrite the output of this field" and set the text value to: [name]
- - Check "Output this field as a link" and set the path to: user/[uid]
Comment #10
arua13l commentedThanks mmilano - worked for me!
Comment #11
michael_lessard_micles.biz commentedI am adding my confirmation of this bug (usernames are truncated when the option "Link this field to its user" is checked).
It applies to version 6.x-3.0 also.
nb: no matter what I try with Views styles/options and CSS, the usernames are truncated, unless I uncheck that option and apply the workaround named by others above (thanks).
Comment #11.0
michael_lessard_micles.biz commentededit
Comment #12
prezaeis commentedthank u so much worked for me
Comment #13
ezoulou commented#9 works just fine. thanks.
Comment #14
Tom Ash commentedCan we add a patch to fix this problem?
Comment #15
jgullstr commentedviews_handler_field_user_name::render_link() is missing the case when "Link to user" is checked and "Use formatted username" is unchecked. This patch considers it by linking the raw data to user/[uid].
Comment #16
cboyden commentedThe previous patch fixed the trimming problem, but after applying it, usernames were double-encoded and displaying HTML entities instead of apostrophes. See screenshot:
The
l()function escapes HTML entities by default, but the text being displayed has already been escaped by therender()function in the parent class. Attached is a new patch which also tells thel()function that the text shouldn't be escaped.Comment #17
hass commentedI do not think this patch is correct.
The "Use formatted username" was made to create the Display Name from username. If disabled, only the username should be shown. This is the expected behaviour I think.
I strongly believe this is code that has been upgraded from D6 and it was missed that D7 has added format_username() in template_preprocess_username(). That was not the case in D6 as I know. Therefore if you check the "Use formatted username" it need to run trough theme_username(). The code need to be removed.
That the username get's truncated is caused by template_preprocess_username() and I think it is bad in sooo many situations that we need to extend core to allow specifying a param to not truncate or at least truncate at a specified letter. This would be a core addition. I think it would be better to push core first and than add another option in views to allow customizing the truncate position. If core does not change we could add a new theme_views_username function and just clone the core function and add the feature there.
Needs work to cleanup the settings to use theme_username if "Use formatted username" is checked and not if unchecked, but than - leave as. I'm in favor of changing the "Use formatted username" to a selectbox that works like D8 formatter with Plaintext and User name.
I'm willingly to review these patches asap and make them RTBC to get rif of #1239478: How to display a user's username (not real name) in Views once RealName is enabled? in Real name module.
Comment #18
hass commentedI'd also like to note #2629286: Use getDisplayName() for user names consistently where I show how many tests are failing and how untested display name feature is. It is D8, but the same exists for sure in D7. The truncating has yielded so many issues... unbelivable.
Comment #19
hass commentedComment #20
jgullstr commentedIf I'm not mistaken, format_username is needed if you want the formatted username without linking to the user.
Comment #21
hass commentedBut you should always use the theme username function. Username theming should work with and without linking.
Comment #22
ronino commentedJust rerolled #16 to work with the latest version.