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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ultimateboy’s picture

Status: Active » Needs review
FileSize
1.49 KB

Patch attached.

mgifford’s picture

#1: user-picture-alt-1875878-1.patch queued for re-testing.

mgifford’s picture

This 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.

phiscock’s picture

Thank 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.

mgifford’s picture

opdavies’s picture

Issue summary: View changes

#4 works for me.

mgifford’s picture

So what needs to happen to mark this RTBC?

opdavies’s picture

I'm not always sure when to mark something as RTBC, different issues seem to need a different number of reviewers.

The patch has received a thorough review and test by one or more experienced developers, and they have deemed it as ready to be committed to the project.

I'm an experienced developer (well, I'd say so anyway), so we could mark it as RTBC?

opdavies’s picture

Issue tags: +affects drupal.org
mgifford’s picture

You're totally an experienced developer. No question.

drumm’s picture

It 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.

sibopa’s picture

Thanks 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.

opdavies’s picture

@sibopa: It's in the Views module, not the User module.

sibopa’s picture

Sorry; 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.

DamienMcKenna’s picture

I suspect it'd take a ton of refactoring to get it to load all users at once.. though there's always entitycache :)

JayDarnell’s picture

#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.

nithinkolekar’s picture

Is 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)

mgifford’s picture

@JayDarnell so you can mark it RTBC if it's someone else's patch.

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.51 KB

looks good,
creds to @JayDarnell and the others.

just rerolling to get rid of some fuzz

DamienMcKenna’s picture

DamienMcKenna’s picture

joseph.olstad’s picture

this is the only issue holding up 3.19
can someone please review? latest interdiff looks good.

joseph.olstad’s picture

nevermind, it's already RTBC, had a look at the patch, this is good, please commit.

  • DamienMcKenna committed 3fc2459 on 7.x-3.x
    Issue #1875878 by DamienMcKenna, joseph.olstad, ultimateboy, phiscock,...
DamienMcKenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Status: Fixed » Closed (fixed)

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