Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I created a content type that includes a user reference field. The view is properly handing that, even with my rewrite to add "/contact" on the end of the link. But I'd really prefer add the (styled) user picture as well. Is there any way to do that?
Comment | File | Size | Author |
---|---|---|---|
#10 | user_picture_styles.patch | 3.48 KB | quicksketch |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedYou should be able to add a relationship from that user reference; once you do, all user fields will become available.
Comment #2
merlinofchaos CreditAttribution: merlinofchaos commentedComment #3
NancyDruIs there no way to apply an image style?
Comment #4
dawehnerSince it's in drupal core this is could be a feature of views.
Comment #5
dawehnerIt's not possible to do nice but you can use hook_preprocess_user_picture for yourself.
Comment #6
NancyDruThanks, Earl and Daniel.
Comment #7
dawehnerIf you want to see why, look here:
Comment #8
dawehnerOnce #1021564: Allow to set image style when using theme('user_picture') is in, this could be implemented.
Comment #9
NancyDruThanks again.
Comment #10
quicksketchI've read up on #1021564: Allow to set image style when using theme('user_picture') and the duplicate issue here: #999050: User: Picture field does not support Image Styles.
Given our situation of waiting on core for a feature that might never come, I'd prefer to implement this feature based on what we have right now. I think #1292470: Convert user pictures to Image Field is more likely to happen before theme_user_picture() takes an image style option, in which case the chance of D7 backport becomes very slim. Even though the foundation for user pictures in core is not ideal, I think making Views support all the abilities core provides out-of-the-box is desirable. Right now a site I'm building is in an awkward situation of using the D7 port of ImageCache Profiles just to get image style support into Views. That shouldn't be necessary.
This patch imitates portions of theme_user_picture() but avoids all the style-specific markup (the alt tags, title text, classes, etc.) If users want to theme their output, they can continue to do that by using the default style and theming it, or rewrite the link, or using a real image field as others have suggested.
Even though the user picture ability in D7 is inferior to a "real" image field, it's what we have in D7. For the sake of theme developers and for new users, I think including more complete support for user pictures should be included in Views.
Comment #11
sirkitree CreditAttribution: sirkitree commentedPatch applies clean and adds a dropdown here:
The desired effect is accomplished as well. When I change the image style on the field, the preview shows the profile image through that image style.
I'm wondering if this should go within the 'Style Settings' fieldset though.
Comment #12
dawehnerYeah, that's cool that' someone took this and implemented it, so this works more or less.
I'm wondering whether it would be possible to still use theme_user_picture if you alter the path to the image.
Commited to 7.x-3.
Comment #13
quicksketchOh geez, I totally just looked at the screenshot and realized I'd labeled the new field "Image preset", doh! That should be "Image style". Everywhere else in the patch is correct, just a little relapse into D6 terminology.
Thanks dereine for your excellent responsiveness. I'll try to reroll tonight.
Comment #14
dawehner@quicksketch
Just changed this string
Comment #15
andypostAs maintainer of imagecache_profiles module I'd like to point that access to user profile should have access check.
Also what is a diffence with previous attempt #750172: User picture always links to user profile
Comment #16
dawehner@andypost
The two issues are fundamental different. This one is about choosing and image style, the other issue was about disabling the link.
You are right, that this addition needs some improvements.
Comment #17
quicksketchDoesn't it already?
Comment #18
andypostThis would cause a lot of discussions like #1107464: user default image doesn't get formatted
This realy does not work if path like
./themes/bartik/logo.png
Let's continie discussion in #1021564: Allow to set image style when using theme('user_picture')
Comment #19
NancyDruCheck the API:
This function is never used; see the corresponding template file instead.
Comment #20
quicksketch@NancyDru: If you were referring to my comment above, "This patch imitates portions of theme_user_picture()", you're right. Calls to theme('user_picture') call template_preprocess_user_picture() and then use the user-picture.tpl.php file. But I don't see what you intended by your comment.
Comment #22
Anonymous (not verified) CreditAttribution: Anonymous commentedJust selected my custom image style which scales and crops the default user picture size of 85x85 down to 40x40.
Selecting 'Default' image style from the drop down works, selecting any other image style (including my custom 40x40 style) results in the image not being rendered.
Using D7.20 and Views 3.5
Anyone else experiencing this problem?
S
Comment #24
tobiberlinI face the same issue - when I choose another preset than "Standard" the image field is rendered empty when viewing the views page:
Using views 7.x-3.5
Comment #25
tobiberlinOk, I found out the following:
In views/modules/user/views_handler_field_user_picture.inc in line 88 the if-check fails:
As I found out
file_valid_uri()
checks if the URI has a valid scheme. I have a public files system so I simply hardcoded such an URI to see if it works - and it worked:Does anyone know how you get the URI with scheme instead of the pictures path from drupal root?
Comment #26
tobiberlinFor me I found a maybe hackish solution... I am not a professional programmer but for know this works for me... I did not find out how you get the stream of a file so I simply did it this way:
Before line 88:
Comment #27
ibustosThe module https://drupal.org/project/default_user_picture_styles attempts to solve this problem.
Comment #28
acidtalks CreditAttribution: acidtalks commentedWith a private filesystem the image url is not correct when using the image style "Standard". Like @tobiberlin said choosing an image style fails too because the uri check returns false. I have modified the building of the pictures filepath and here is a patch which works for a private filesystem. Please test with a public filesystem.
Patch is based on Views 7.x-3.8.