The code in views/modules/user/views_handler_field_user_picture.inc

  function render($values) {
    // Fake an account object.
    $account = new stdClass();
    $account->uid = $values->{$this->aliases['uid']};
    $account->name = $values->{$this->aliases['name']};
    $account->picture = $values->{$this->field_alias};

    return theme('user_picture', $account);
  }
}

I want to say, "there's no check to see if the user specified a link"... but that kind of fix would be complicated.

How about a theme('user_picture_plain', ...) which returns an unlinked photo?

Comments

dawehner’s picture

If you remove the uid, only the image get displayed: http://api.drupal.org/api/function/template_preprocess_user_picture

Thats out of scope of views, but you could make a patch to make it configurable.

fizk’s picture

Nice! I think it's within the scope of views to have this as a configurable option.

fizk’s picture

So the option would be something like,

Use default theming for user's photo:

  • Yes. (Default)
  • No. (this will remove the link to the user's profile

or even simplier

Link to user's profile:

  • Yes. (Default)
  • No.
dawehner’s picture

I would do the second one... Additional i'm again theme('user_picture_plain', ...)

fizk’s picture

Great, I can create a patch if you agree it's within view's scope?

fizk’s picture

Looking at imagecache_profiles:


class imagecache_profiles_handler_field_user_picture extends views_handler_field_user_picture {
  ...
  ....

  function render($values) {
    // Fake an account object.
    $options = $this->options;
    $account = new stdClass();
    $account->uid = $values->{$this->aliases['uid']};
    $account->name = $values->{$this->aliases['name']};
    $account->mail = isset($values->{$this->aliases['mail']}) ? $values->{$this->aliases['mail']} : '';
    $account->picture = $values->{$this->field_alias};

    if ($options['imagecache_preset']) {
      $account->imagecache_preset = $options['imagecache_preset'];
    }

    return theme('user_picture', $account);
  }
}

Means that we need to have $values->{$this->aliases['uid']} return NULL for subclasses of views_handler_field_user_picture when our new option is set.

Or modify $values.

fizk’s picture

Yaay, this works:

class views_handler_field_user_picture extends views_handler_field {
  function construct() {
    parent::construct();
    $this->additional_fields['uid'] = 'uid';
    $this->additional_fields['name'] = 'name';
  }

  function element_type() {
    return 'div';
  }

  function pre_render($values) {
      if (true) {
          foreach($values as $value) {
              $value->{$this->aliases['uid']} = NULL;
          }
      }
  }

  function render($values) {
    // Fake an account object.
    $account = new stdClass();
    $account->uid = $values->{$this->aliases['uid']};
    $account->name = $values->{$this->aliases['name']};
    $account->picture = $values->{$this->field_alias};

    return theme('user_picture', $account);
  }

All we have to do is change the "if (true)" to an option.

fizk’s picture

StatusFileSize
new1.22 KB

and the patch! :)

fizk’s picture

Status: Active » Needs review
fizk’s picture

StatusFileSize
new1.22 KB

oops, default value wasn't correct.

fizk’s picture

Testing with three user photo fields shows that foreach($values as $value) { isn't right....

how to get the option <==> values pair for each field in pre_render()?

fizk’s picture

StatusFileSize
new1.2 KB

We could make the change in render(), and bug the imagecache_profile maintainers to update their code.

dawehner’s picture

Status: Needs review » Needs work
+    $options['link_photo_to_profile'] = array('default' => 0);

Its a boolean so make a boolean as default.

+        0 => t('Yes'),
+        'no_link' => t('No'),

Choose boolean values here.

+    if ($this->options['link_photo_to_profile'] == 'no_link') {
+      $values->{$this->aliases['uid']} = NULL;
+    }

Use boolean here... I'm not sure about NULL, does it the same as unset?

fizk’s picture

Status: Needs work » Needs review
StatusFileSize
new1.17 KB

unset works too. Here's an updated patch using boolean.

dawehner’s picture

A inline comment would be cool, why unsetting the uid here removes the link

fizk’s picture

StatusFileSize
new1.26 KB

done.

finex’s picture

subscribing

fizk’s picture

Can someone please test and commit this ASAP?

finex’s picture

I've just tried the patch but it doesn't work. The form is added on the configuration, but the link is not removed.

dawehner’s picture

Status: Needs review » Needs work

So needs work

walden’s picture

subscribing

fizk’s picture

FiNeX, do you have imagecache_profiles module installed? If you do, please disable it and test again.

fizk’s picture

dereine, does it work for you?

fizk’s picture

walden, does it work for you?

finex’s picture

@fizk: Yes, I have imagecache_profiles installed. Without it the patch is ok...

fizk’s picture

Status: Needs work » Reviewed & tested by the community

Finex, thanks!

dereine, can you commit?

dawehner’s picture

No i cannot commit.

dawehner’s picture

Status: Reviewed & tested by the community » Needs review
+++ modules/views/modules/user/views_handler_field_user_picture.inc	2010-03-23 17:06:32.000000000 -0400
@@ -15,7 +15,31 @@
+    $options['link_photo_to_profile']['default'] = 1;

more minor: we should use array('default' => 1) because its done this way everywhere in drupal.

+++ modules/views/modules/user/views_handler_field_user_picture.inc	2010-03-23 17:06:32.000000000 -0400
@@ -15,7 +15,31 @@
+    return $options;
+  } ¶
+  ¶
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state); ¶

some minor spaces

+++ modules/views/modules/user/views_handler_field_user_picture.inc	2010-03-23 17:06:32.000000000 -0400
@@ -15,7 +15,31 @@
   function render($values) {
+    if (!$this->options['link_photo_to_profile']) {
+      // Prevent template_preprocess_user_picture from adding a link by unsetting the uid.
+      unset($values->{$this->aliases['uid']});
+    }
+
     // Fake an account object.
     $account = new stdClass();
     $account->uid = $values->{$this->aliases['uid']};

So we set $account->uid with a NULL? Is it isset or "" afterwards?

I might think that this could/will lead to errors when a user try to load the account of a picture which will be done.

Powered by Dreditor.

dawehner’s picture

Additional you cannot RTBC your own patch, thats my oppinion :)

fizk’s picture

So we set $account->uid with a NULL? Is it isset or "" afterwards?

I think isset($account->uid) would return FALSE.

I might think that this could/will lead to errors when a user try to load the account of a picture which will be done.

I'm not sure what you mean. The $account variable is only used for theme('user_picture', $account);

fizk’s picture

Additional you cannot RTBC your own patch, thats my oppinion :)

You should get the infrastructure team to remove the issue creator's ability to RTBC ;)

idflood’s picture

subscribing

verta’s picture

subscribing

capaneus’s picture

subscribing

dawehner’s picture

Status: Needs review » Needs work

I think needs work is the right status.

michellezeedru’s picture

Subscribing

verta’s picture

Willing to test a patch, if one is available, we could use this feature.

dawehner’s picture

See #17 for the patch. If the patch works this is fine. But there are still code issues which was reported above.

fizk’s picture

dereine, what are the code issues?

verta’s picture

I can confirm that the patch in #17 does add the UI to make linking to the profile optional, and it works to remove the hyperlink.

One downside is that if you do not link to the profile the ALT tag does not using the Real Name (if you hover over the photo you get "userid's photo" - if you do link to the photo, you get the Real Name. (Perhaps because that sends it through the theming functions.) It would be a better patch without this side effect on the ALT in the IMG tag, just my opinion, realizing that it's more complex to try to separate them.

Because we need ImageCache, with or without the helper module referenced, we have added a photo field to the profile, populated it with the table wizard and we're using that field in our view.

dawehner’s picture

Status: Needs work » Postponed (maintainer needs more info)

Is there a reason why the realname module does not override the handler?

Apfel007’s picture

subscribe

esmerel’s picture

I'm going to give this one more month to get finished, otherwise, I'm going to close it.

verta’s picture

This issue may possibly be a duplicate, #720772: "User: picture" link cannot be changed, where there is some code posted?

fizk’s picture

esmerel,

All the issues for the patch have been fixed. As far as I know, it's been tested by a few people other than me and works. You can commit this to CVS if you have commit rights.

bcobin’s picture

Applied the patch in #17 and whereas it adds a select option not to link to the user's profile, the setting has no effect - pictures are still linked to the profile and link override likewise has no effect. Disabling Imagecache Profile Pictures doesn't fix the forced link either.

merlinofchaos’s picture

All the issues for the patch have been fixed. As far as I know, it's been tested by a few people other than me and works. You can commit this to CVS if you have commit rights.

fizk: dereine posted a very clear review in #29. Nothing in #29 has been addressed. Therefore, 'needs work'.

esmerel’s picture

@46: dereine and merlinofchaos have the final say on code commits, so no, I'm not committhing anything even though I have the ability to do so. If dereine's question in @42 was answered adequately by 47, then I think he can change this to rtbc. However, I am not sure his question was answered.

fizk’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Sorry, I don't have time to work on this patch.

Please reopen only if you can fix and commit as requested by merlinofcaos and dereine.

Michsk’s picture

Status: Closed (won't fix) » Needs work

fizk: what kind of funding would you need to fix the small issues ment before in the patch?

Michsk’s picture

We should also make this work with the default avatar, if a user has not yet chosen / uploaded a own avatar.

fizk’s picture

StatusFileSize
new1.27 KB

The patch works for me on a fresh install of Drupal 6.22 and Views 6.x-2.12.

more minor: we should use array('default' => 1) because its done this way everywhere in drupal.

Fixed.

some minor spaces

Fixed.

So we set $account->uid with a NULL? Is it isset or "" afterwards?

!isset($account->uid) returns TRUE
empty($account->uid) returns TRUE
$account->uid === null returns TRUE
$account->uid == '' returns TRUE
$account->uid !== '' returns TRUE

I might think that this could/will lead to errors when a user try to load the account of a picture which will be done.

Only if using $account->uid before checking if it has a value. For example, in template_preprocess_user_picture, a check is made to see if it's empty: if (!empty($account->uid) ...

Michsk’s picture

Your awesome man! Thanks for this.

// will do the testing later on today.

hydra’s picture

StatusFileSize
new1.73 KB

The patch first looked fine, but unsetting $values->{$this->aliases['uid']} could might make trouble to other fields, wich will use this variable, for example the title field. Disabeling the link on the userpicture would cause, that the title link to the user would be broken.

    if ($this->options['link_photo_to_profile']) {
      // Prevent template_preprocess_user_picture from adding a link by unsetting the uid.
      $account->uid = $values->{$this->aliases['uid']};
    }

This should prevent this.

hydra’s picture

Status: Needs work » Needs review

status update

fizk’s picture

Status: Needs review » Needs work

Thanks Hydra, that makes sense.

+++ b/modules/user/views_handler_field_user_picture.inc
@@ -9,21 +9,45 @@ class views_handler_field_user_picture extends views_handler_field {
     parent::construct();
     $this->additional_fields['uid'] = 'uid';
     $this->additional_fields['name'] = 'name';
-    $this->additional_fields['mail'] = 'mail';   
+    $this->additional_fields['mail'] = 'mail';
   }
 
   function element_type() {
     return 'div';
   } 

Should be removed.

hydra’s picture

Status: Needs work » Needs review
StatusFileSize
new1.42 KB

Hell yeah :) okay here it is
Please review, d7 Patch is already waiting

fizk’s picture

Iasac, does #58 work for you?

Michsk’s picture

Going to test it tomorrow.

dawehner’s picture

This patch seems to look fine, but in general i'm wondering whether this still be applied to 6.x-2.x, as from my perspective this doesn't seem to be a bug of views, but a feature request.

hydra’s picture

Category: bug » feature

indeet! This is defenetly a feature request, overread this.

dawehner’s picture

Version: 6.x-2.8 » 6.x-3.x-dev

And it's only against 6.x-3.x and later. There are no new feature requests for 6.x-2.x

Michsk’s picture

well it doesn't seem to work, but that offcoures might have to do with imagecache profiles

Michsk’s picture

Yap, this option does not work with imagecache profile

Michsk’s picture

The patch is tested and works. I will post a link to this threat in imagecache profile

hydra’s picture

Version: 6.x-3.x-dev » 6.x-2.8

The patch is working for 6.2, but how dereine sayed, it has to work with 6.3 to be commited, I will post a new patch later, if I have time. For all people who need this in 6.2, the patch will do it

hydra’s picture

Version: 6.x-2.8 » 6.x-3.x-dev
StatusFileSize
new1.53 KB

Okay here now the 6.x-3 patch. I replaced the radiobuttons with a checkbox, because every other option is handled with checkboxen too. Additionally I added a little description to the field in the ui.

Michsk’s picture

Checkboxes sound unlogic, since you can only make one choice.

hydra’s picture

Well, probably you havent noticed, but every "single choice" in views is a checkbox. It would be inconsistent to use radiobuttons now and would not make sense.

hydra’s picture

StatusFileSize
new1.42 KB

Okay a few little changes here. After switching from radio-buttons to checkbox the options are pretty much useless. I changed the comment above, becuase the uid is not longer unsetted, its just not set.

dawehner’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Needs review » Patch (to be ported)

So commited to 6.x-3.x
Thanks for the work!

This should probably be ported to d7

hydra’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Patch (to be ported) » Needs review
StatusFileSize
new1.41 KB

Here is the patch for D7, its probably the same, I'm not quite sure if this is right, but it works all fine in UI

hydra’s picture

StatusFileSize
new1.17 KB

okay, here a better version

hydra’s picture

StatusFileSize
new1.42 KB

Lool, missing header...

dawehner’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Needs review » Fixed

Thanks again! Commited to 7.x-3.x as well.

Status: Fixed » Closed (fixed)

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

Toktik’s picture

Category: feature » bug
Status: Closed (fixed) » Active

Using 7.x-3.1 and having this problem. I am still unable to Rewrite user picture link.

dawehner’s picture

Status: Active » Closed (fixed)

I'm sorry but this is not scope of the issue.

As views is not generating the link it can also not control the link.

pipep’s picture

I had to deal with the same issue. I'm on D7. 12 and views 3.1.

I have a view for showing comments, with relationship with comment:author and comment:content.

The fields I wanted to show were user:picture, user:name, comment: post date, comment:comment, content:delete link, content: title, comment: view link.

User:picture has the link to user's profile disabled but still generates the link.

I solved this making a wrapper div for the hole view, and with jquery converting it to a clickable div with higher z-index than the pic, so even if u click on the pic it takes u to the comment and not to the user.

Marc Ledergerber’s picture

Status: Closed (fixed) » Fixed
Issue tags: +Drupal 7.x, +How to remove links to user profile from a user picture (image), +Views 7.x-3.5
StatusFileSize
new87.54 KB
new12.3 KB

This is a very quick, easy way to prevent a user picture from linking to a user profile. Use case scenario is a custom View that generates a directory of community members and you just want the images of your community members to be displayed without links back to their respective profile pages. Simply modify the configuration for the field "User: Picture" to customize your view.

Summary: Utilize Drupal Views and the built-in customization settings to "REWRITE RESULTS" and selectively "Strip HTML tags". Doing this effectively removes the <a> tag (which includes the href attribute) on "User: Picture" images that would otherwise print and thereby create links to users' profiles.

  • Users' profile images are displayed, but with no links to the respective user's profile page.

How to remove the <a> tag from users' images on your View to prevent a link to users' profiles.

[The attached screen shots illustrate these quick, easy configuration steps for Views 7.x-3.5.]

Step #1: Go to yourdomain dot whatever/admin/structure/views/view/nameofyourview/edit

Step #2: Edit View for User Picture Field

  • Under Fields, click on "User: Picture"
  • Scroll down to "Rewrite Results" and click "Strip HTML tags" (this removes <a href="URL">)
  • In the text field "Preserve certain tags", specify: <div> <img> (add just the particular HTML tags required for your customized configuration)
  • Click "Apply (this display)"
  • Click "Save"

Step #3: Reload your view (page/block). User images display fine with no links to profile page.

Version: 7.x-3.x-dev » 7.x-3.5
Component: Code » Documentation
Assigned: Unassigned » Marc Ledergerber
Category: bug » support

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

Status: Fixed » Closed (fixed)

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

jvieille’s picture

Issue summary: View changes

Never committed to D6 apparently (Views 2)
Made a mix between #57 and #75

Marc Ledergerber’s picture

For Drupal 7.43+ with Views 7.x-3.13+, solution described in #81 is confirmed. Views has been included in Drupal 8 core, so this is even easier to implement in Drupal 8.

For an example implementation, see https://ediscoverypeople.com