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.
{
"user" : {
"name" : "yu123456789",
"uid" : "11",
"picture" : " \n \n"
}
},
all user picture path cann't display.
Comment | File | Size | Author |
---|---|---|---|
#13 | view.png | 188.87 KB | anthonylindsay |
#11 | person__User____Drupal_standard.png | 230.68 KB | anthonylindsay |
Comments
Comment #1
g089h515r806 CreditAttribution: g089h515r806 commentedI have the same issue.
Comment #2
coolman7 CreditAttribution: coolman7 commentedI have same issue.
Comment #3
Strutsagget CreditAttribution: Strutsagget commentedseems to be there still
Comment #4
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedSadly I just spent about 2 hours on this and wasn't able to solve it. Here are the major players (in relative order AFAIK):
This spans through Views JSON, to Views, to Drupal core. I've placed a bunch of watchdog messages along the way and the picture seems to be built just fine, but the images always gets rendered as an empty string in the render function in views_handler_field_user_picture.inc:
Oddly, if you switch the Views Format to table, the picture will be displayed, but watchdog still reports the output as an empty string in views_handler_field_user_picture.inc.
I'm starting to wonder if the fact that theme_user_picture() doesn't exist, and instead it gets fed to the preprocessor and ultimately to user-picture.tpl.php has anything to do with it.
Comment #5
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedComment #6
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedHere's a workaround:
Replace the values in $views_to_process with your View's machine name(s), the name of your uid and picture columns, and the name of your image style. You can add more than one view to process.
Comment #7
dr-wanni CreditAttribution: dr-wanni commented@tyler.frankenstein where do i put the above code, in views_datasource/views_json.module?
Comment #8
tyler.frankenstein CreditAttribution: tyler.frankenstein commented@dr-wanni in a custom module: https://www.drupal.org/developing/modules/7
Comment #9
ultrabob CreditAttribution: ultrabob commentedThanks tyler.frankenstein, this was a godsend. The code above assumes you have root and child names set. If you don't then you'll need to modify the code just a little bit to remove the extra root and child levels:
Comment #10
coolman7 CreditAttribution: coolman7 commentedTry this module:
https://www.drupal.org/project/views_upu
It worked for me.
Comment #11
anthonylindsay CreditAttribution: anthonylindsay at Annertech commentedI don't think there's anything wrong with the module: if you get \n\n outputs, the chances are that you are outputting your JSON as plaintext.
If you turn off plaintext output you should get the desired output.
Have a look at the attached screenshot.
Comment #12
tyler.frankenstein CreditAttribution: tyler.frankenstein commented@anthonylindsay thank you for the reply. Turning off the "Plaintext output" does return the HTML for the profile picture. I'd say this isn't very useful for consumption since applications will probably want to render it their own way.
I believe most are looking for, and the way it used to work just prior to the alpha 1 release, is to output the src of the picture including the image style (but at the same time embrace the new format that is used when outputting image fields, i.e. include the alt/title, even though there probably isn't any).
I'd vote to keep this issue active, but I understand if you wish to close it. Please advise, thanks.
Comment #13
anthonylindsay CreditAttribution: anthonylindsay at Annertech commentedI had another go at this and had some success with it using a relationship: "File Usage: File". This gave me access to the path and alt text. Now, the path did not respect the image style, so that wasn't ideal. I was also able to strip down the returned HTML for the image to a very minimalist image tag, with none of Drupal's usual wrapper gunk by changing the view field settings. I also tried the views_upu module, and that does a nice job of allowing you to output the url of the picture, respecting the image style.
Have a look at the attached screenshot: you'll see an alt text field (alas there's no content for it, but still) and a path field, and the minimalist img output. That's what we get out of the box. With the addition of views_upu you can extract the img src and display just that. I think I'd like to call this one closed, given the data we can access with the file usage relationship and what views_upu can bring to the table. And for those with needs unfulfilled by the modules, Tyler's preprocess hook does offer more options.