When a user picture field is placed in views, the alt attribute is only visible if the default image style is selected. However, if you choose a different image style, views_handler_field_user_picture.inc just passes the file uri directly in to theme_image_style() which means you dont get the alt text on that image.
From my point of view, the best way to get this in there is to do a user_load() and then create the alt text similar to how theme_user_picture() does. I'm hoping the user_load() here isn't too much. We could "fake" it sense we know the username, but not doing the user_load() would mean we couldn't run through format_username() to allow others to alter what is rendered.
Comment | File | Size | Author |
---|---|---|---|
#20 | views-n1875878-20.interdiff.txt | 1.38 KB | DamienMcKenna |
#20 | views-n1875878-20.patch | 1.04 KB | DamienMcKenna |
|
Comments
Comment #1
ultimateboy CreditAttribution: ultimateboy commentedPatch attached.
Comment #2
mgifford#1: user-picture-alt-1875878-1.patch queued for re-testing.
Comment #3
mgiffordThis seems to apply on http://simplytest.me
Can you export a view with this to make it easier to test? This sounds like it would be a bug in D8 as well.
Comment #4
phiscock CreditAttribution: phiscock commentedThank you very much for addressing this problem which had been bugging me.
However, the patch in #1 isn't quite right. It doesn't call the user account correctly and therefore writes the alt tag as Anonymous's Picture.
I have corrected the patch and attached a revised version which is working for me.
Comment #5
mgifford4: user-picture-alt-1875878-4.patch queued for re-testing.
Comment #6
opdavies#4 works for me.
Comment #7
mgiffordSo what needs to happen to mark this RTBC?
Comment #8
opdaviesI'm not always sure when to mark something as RTBC, different issues seem to need a different number of reviewers.
I'm an experienced developer (well, I'd say so anyway), so we could mark it as RTBC?
Comment #9
opdaviesComment #10
mgiffordYou're totally an experienced developer. No question.
Comment #11
drummIt would be ideal to load the users all at once with
user_load_multiple()
, or ensure the name is available in the queries Views does already. Loading one at a time makes a bunch of small queries, a bunch of round trips to the DB that add up. I'm tempted to say this needs work, but I'll leave that for a Views maintainer.The ideal way to solve this would be ensuring
{users}.name
in in the query Views does. That is effectively zero additional overhead, and I would not expect benchmarks.Comment #12
sibopa CreditAttribution: sibopa commentedThanks for this patch;
I was trying to use it and can't find "views_handler_field_user_picture.inc" in the user module. What don't I understand here?
Thanks.
Comment #13
opdavies@sibopa: It's in the Views module, not the User module.
Comment #14
sibopa CreditAttribution: sibopa commentedSorry; disregard my previous post.
I was looking for the "views_handler_field_user_picture.inc" in the core user module instead of the "views/module/user".
Thanks again.
Comment #15
DamienMcKennaI suspect it'd take a ton of refactoring to get it to load all users at once.. though there's always entitycache :)
Comment #16
JayDarnell#4 worked for me. Can we please get this committed?
Apologies for the unnecessary additional patch file upload. I created my own after #4 wouldn't apply for me initially but that ended up being an error on my end. #16 is essentially a duplicate.
Comment #17
nithinkolekar CreditAttribution: nithinkolekar commentedIs this issue still valid? because alt text for user picture is rendering properly in view for all styles without applying this patch.sorry wrong alert :( .
Letter Default Avatar module is installed which sets the alt tag overriding hook_preprocess_user_picture.
patch #16 work perfectly.
It took long time to issue gets committed. So before committing could we add title attribute too?(just to make it theme friendly which supports hover text from title attribute)
Comment #18
mgifford@JayDarnell so you can mark it RTBC if it's someone else's patch.
Comment #19
joseph.olstadlooks good,
creds to @JayDarnell and the others.
just rerolling to get rid of some fuzz
Comment #20
DamienMcKennaI moved the two new lines inside the if() statement where the $alt variable is actually used.
Comment #21
DamienMcKennaComment #22
joseph.olstadthis is the only issue holding up 3.19
can someone please review? latest interdiff looks good.
Comment #23
joseph.olstadnevermind, it's already RTBC, had a look at the patch, this is good, please commit.
Comment #25
DamienMcKennaCommitted.