More on views

rclemings's picture

I'm still missing something on the views issue I was having last week (i.e. trying to get the logged-in users ID into a views 6.2 field). I've got "global $user; return $user=>uid;" as the default argument PHP and "user/%1/user_mailman_register" as the link path on the field. But the link that gives me is "user/Uncategorized/user_mailman_register" so I guess it's not picking up the uid. Can anyone see what I'm doing wrong? I created a stripped-down version of the view and put an export of it here: http://pastebin.com/3eHP0Nbf

Comments

Try these changes

lowtrak's picture

I don't recall the specific reason why PHP code was needed for the default argument just to get the user id, but you can do the same thing by setting the default argument type to "User ID from logged in user." It's pretty much the same thing as returning $user->uid. Also, just in case you were needing the php code for some expanded condition, please note you have a typo in your view code; it should be $user->uid instead of $user=>uid.

Other than that, try changing your link path to: user/!1/user_mailman_register. That will make sure you're getting the right input from the argument.

A couple of other things to note:

  1. Since you're using a default argument, the output from the view will filter based on that user id. This may be what you want, but it's not clear from the example.
  2. If the display from this view is public, anonymous users will get a link like "user/0/user_mailman_register". Pretty sure that's not what you want, so you should restrict visibility to signed in users. Again, not clear on how you're using the view so you may have this covered.

Hope that helps!

Actually, no, I don't want to

rclemings's picture

Actually, no, I don't want to filter the view. I just want to use the UID to create a link to the mailing list subscriptions tab on the user's profile page. Is there any way to pass the uid to a link without filtering?

With regards to the filtering

lowtrak's picture

With regards to the filtering issue, there are several ways to do this if you don't need to mess with arguments. The easiest (and what I use most often since I usually have the module installed) is to use the views_customfield module. That will allow you to add almost anything you could possibly need in a field and is really flexible. In your case I would:

  1. Remove the argument, since it will not be needed.
  2. Install the views_customfield module.
  3. Replace your custom text field with a "Customfield:PHP code" field.

For the value, add the PHP snippet mentioned earlier. Actually, a better way to do this would be something like:

<?php
global $user;
return
l(t('My link'), 'user/'.$user->uid.'/user_mailman_register');
?>

That should show all of the unfiltered results, but still have links that point to the current user's mailman register page.

Yep, that seems to work, at

rclemings's picture

Yep, that seems to work, at least on my little test page. I'll try it on the real view over the weekend if time permits.

Much obliged. I was thinking I would have to write a custom module, which would take me roughly forever. I should have know somebody already did it.

Maybe I should ask for a future session on "is there a module to do that (whatever that is)" ...

rac

Closing the loop on another

rclemings's picture

Closing the loop on another thread, views_customfield worked great for this. You can see it in action here: https://www.nasw.org/discussions ... if you're anonymous, you should see a link that says "log in to subscribe," but if you create a username and log in, you will see a "subscription options" link that takes you to the appropriate tab on your user profile (the one generated by the user_mailman_register module).