Hi

I was setting up a view of recent comments that displayed the User picture as one of the view fields.

When there was no User picture available I still wanted to show a default image.

So I went to the “Account Settings” page at /admin/config/people/accounts and entered a URL in the “Default picture” field under the “Personalization” fieldset.

I’m new to Drupal, so I moved a picture to sites/default/files and tried the URL as “sites/default/files/defaultuser.jpg” as that’s what made sense to me as a URL.

Of course that did not work, because the field was expecting a path in the Drupal file streams format, e.g “public://defaultuser.jpg”.

To a new user like me, the requirement to use public:// was impossible to know, and impossible to even Google for as I was unaware of this concept.

So I suggest a small patch to make this clearer for new users, changing the field description from:

“URL of picture to display for users with no custom picture selected. Leave blank for none”

to:

“URL of picture to display for users with no custom picture selected. This will usually be something like “public://yourimage.jpg” for an image in sites/default/files. Leave blank for none”

This new description is much clearer, and at least gives a user an important piece of information “public://” to google for if they get stuck.

I'm sure there are others, but here is one example of new users becoming confused due to this in the following issue:
#1442470: User profile picture styles doesnt work.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Salah Messaoud’s picture

Status: Active » Needs review
FileSize
801 bytes

Patch attached

David_Rothstein’s picture

Version: 7.16 » 8.x-dev
Status: Needs review » Needs work

Thanks for the patch! It would need to go into Drupal 8 first, though. (And since this is a string change I'm not sure it would be backported to Drupal 7, although it's an admin-facing string, so maybe: http://drupal.org/node/1527558.)

Of course that did not work, because the field was expecting a path in the Drupal file streams format, e.g “public://defaultuser.jpg”.

I don't think it necessarily expects that (in fact, I didn't even know it works). An actual URL works fine here also, like http://example.com/sites/default/files/whatever.png (where http://example.com is replaced with the URL of your site). I think that's probably the intention of this field.

It's a neat trick that you can use a stream wrapper too (and there are some advantages to doing so since it's portable if you move your site to a different server, e.g. dev to staging to live, and sounds from your other link like there are other use cases too?). But it might be too advanced to document in that much detail here.

David_Rothstein’s picture

Part of the problem with this field might also be that it doesn't seem to have any good error feedback if you do enter something invalid (like sites/default/files/defaultuser.jpg). It seems like it just fails silently.

David_Rothstein’s picture

Also, in my testing, typing "sites/default/files/defaultuser.jpg" directly actually does work (provided that the file exists). It only seems to be a problem if the file doesn't exist in the first place?

willieseabrook’s picture

Salah and I set up a clean environment to retest with, and you are correct, the user.module is not broken, because it accepts URLs of both types - "sites/default/files/defaultuser.jpg" AND "public://defaultuser.jpg".

This is actually an issue with the inconsistent ways contrib modules are formatting the user picture. In this specific case, it was the views User picture display handler

In /views/modules/user/views_handler_field_user_picture.inc


  function render($values) {
    if ($this->options['image_style'] && module_exists('image')) {
      // @todo: Switch to always using theme('user_picture') when it starts
      // supporting image styles. See #1021564
      if ($picture_fid = $this->get_value($values)) {
        $picture = file_load($picture_fid);
        $picture_filepath = $picture->uri;
      }
      else {
        $picture_filepath = variable_get('user_picture_default', '');
      }
      if (file_valid_uri($picture_filepath)) {
        $output = theme('image_style', array('style_name' => $this->options['image_style'], 'path' => $picture_filepath));
        if ($this->options['link_photo_to_profile'] && user_access('access user profiles')) {
          $uid = $this->get_value($values, 'uid');
          $output = l($output, "user/$uid", array('html' => TRUE));
        }
      }
      else {
        $output = '';
      }
    }
    else {
      // Fake an account object.
      $account = new stdClass();
      if ($this->options['link_photo_to_profile']) {
        // Prevent template_preprocess_user_picture from adding a link
        // by not setting the uid.
        $account->uid = $this->get_value($values, 'uid');
      }
      $account->name = $this->get_value($values, 'name');
      $account->mail = $this->get_value($values, 'mail');
      $account->picture = $this->get_value($values);
      $output = theme('user_picture', array('account' => $account));
    }

Because of the check using file_valid_uri, the output is set to '' (nothing) in certain circumstances, which is what we were seeing in our original setup (a View of User comments with a User picture). This is a situation in which you must have the default file URL in the format of public://

So, what should we do here?

Perhaps we create a separate issue in the views module?

In addition, it still might be worthwhile improving this admin string, by still saying that the default image can accept a URL using the Drupal streams format (e.g of public://) and thereby helping new people learn the Drupal way quicker?

Let us know what you think.

swentel’s picture

Version: 8.x-dev » 7.x-dev

User picture is a field now in D8, moving to D7, although I'm not sure this will get in.

Anybody’s picture

+1 for this! I just ran into the described problem and entered a normal file path. The picture showed up but was never displayed correctly.

I would have saved hours if a little sentence would have described that everything works fine if I use as stream wrapper URL.
So please please just add a bit more documentation. This is really frustrating and besides all discussion, does it really need two years to add a useful sentence or hint?

Also, in my testing, typing "sites/default/files/defaultuser.jpg" directly actually does work (provided that the file exists). It only seems to be a problem if the file doesn't exist in the first place?

I can not confirm this (and I tested it!). The file works but is never being processed by the selected image style. And that's the key point...

Anybody’s picture

I just ran into the same problem again because I had forgotten this "§$%&§§ ;) ;)

Please please fix the fields description and safe lifes :)