using
views-6.x-2.1
Drupal 6

Created some new views, added fields and when adding an Argument i just cant find the option "User: UID is Author" anymore, was it removed?

Comments

akbonker’s picture

i am curious about this too. this argument is not available in the views module as far as i can see.

Anonymous’s picture

What do you mean by User: UID is Author? when you have an argument User: UID, If you pass a UID the result for sure is the content of the author.

or are you trying to view only the content for the current user?

trevorsheridan’s picture

You can achieve this in Views2 by creating a Filter and selecting "User: Current", and setting it's option to Yes. I left my filder unexposed.

Your situation may vary, but I used this in Views1 on Drupal 5 to show a list of nodes a user created under a view I named "My Listings". In Drupal 6 I used the method above to achieve this on a project with similar requirements.

Trevor
www.trevorsheridan.com

agenciadroopi’s picture

yes thank you it works this way, using filters

Marko B’s picture

Thinks both filter and argument can be used for this.

In argument you just paste default value and then put UID from logged in user.

mudd’s picture

No, this is absolutely not the same. If the logged in user is editing somebody else's node, then User: Current is different from User: UID is Author.

I'm struggling with issue because I need to allow administrative roles edit Users' nodes. AND I _require_ a node reference field that's filtered to A) another content-type, and B) only node owned (authored) by the same user. This works fine when a user is creating/editing nodes. But when an Admin edits somebody else's node, the required node-reference field breaks horribly: The previous value is not shown due to the filter, and if the admin doesn't choose a new value, Drupal decides that no selection has been made and won't allow the form to be saved.

Some have suggested using arguments, but alas the suggestion was like five words with no explanation of how to go about it. (and I've tried tirelessly)

handsofaten’s picture

I'm having the same problem, trying to fix it using User: UID argument, but not having much luck. I can use PHP code to return the UID for the logged in user, and I figured once I get to that point, I could somehow override the argument to show all values in the node_reference field if the logged in user is admin. But that "somehow" is stumping me.

I was trying something like this (but I don't think 'all' is an acceptable value to return on the last line -- that would just override the argument before processing):

global $user;
$uid = $user->uid;

$admin = false;

$allowed = array('Administrator','Editor');

foreach($user->roles as $role){
  if(in_array($role, $allowed)) {
      $admin = true;
  }
}

if(!$admin){
  return $uid;
}else{
  return 'all';
}
handsofaten’s picture

I have solved the very specific problem of admins (ironically) not being able to save changes to nodes with CCK node reference fields that use Views to display only nodes of a certain type that were created by the logged in user. I would prefer to have the admin be able to see all nodes of the type being referenced, but I can't figure that out.

Instead, I am checking to see if this is an admin user editing a node, and if so use the UID of the node's creator in the argument (as opposed to the logged in user). In the User: UID argument, select "Provide default argument" and then "PHP Code" under Default argument type.

Use this code:

global $user;

$admin = false;

$allowed = array('administrator','editor');

foreach($user->roles as $role){
  if(in_array($role, $allowed)) {
      $admin = true;
  }
}

if($admin == true && arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit'){
  $nid = arg(1);
  $node = node_load($nid);
  return $node->uid;
}else{
  return $user->uid;
}

This checks to see if the currently logged in user is an admin or an editor, and if so it checks to see if that user is editing a node. If all of these conditions are true, then it uses the UID of the creator of the node as the argument, instead of the logged in user. Otherwise, it uses the logged in user. This way, if the administrator is editing someone else's node, they will get the same choices in that node reference field as if they were the original creator of the node.

eg2234’s picture

Hey, thanks for this, I had pretty much the identical situation and was tearing my hair out trying to outsmart Drupal.

WebNewCastle’s picture

I don't know where "User: UID is Author" went in Views 2, and I was confused about this for a while. But as Inocram stated a few months ago, you an still get this to work if I am understanding correctly what you are trying to do. As Mudd later mentioned, "User: Current" is different than "UID is Author".

So what I was working on was to just user Views to do a quick customization of the User Profile page (rather than using another module or coding a user-profile.tpl.php file). One of the things I needed was to list content authored by the User whose profile is being viewed (not blog content which is there by default).

I set-up a simple "User: UID" argument in the View. In my filters, I have it limited by Note Type = xxx, etc. The simple argument that I have set-up does two things that I need. One is to handle the override of the default User Profile page, and the other is to essentially "filter" some of the content I want displayed on the custom profile page - i.e. to list content authored by the User's whose profile pulled up.

If this is similar to what you are trying to do, then it works with that Argument and without "User: UID is Author".

- Matt
http://WebNewCastle.com

mudd’s picture

The key for me was that I needed to view a list of nodes by the author of a node I'm viewing, which is not necessarily one of my own nodes. An example of this in your case might be that when your admin views a user's profile they see a list if that user's nodes.

The answer to this (should you ever need it) is here: http://views-help.doc.logrus.com/help/views/example-author-block. The only missing bit in this recipe is that under "Validator options | Type of user argument to allow:" none of the options get picked by default, so I chose "Allow both numeric UIDs and string usernames".

manop’s picture

In my case, I retrieved the argument from the page title since the title is the name of user. I use the code below in Views' argument.

$args = drupal_get_title();
return $args;

ressa’s picture

Thanks manop, just what I needed, with "User: UID is Author" gone.

Here's how to build the argument:
- Make a new argument, select the 'User: Name' field.
- Under 'Action to take if argument is not present:' select 'Provide default argument'
- Under 'Default argument type:' select 'PHP Code'
- Paste in the code:

$args = drupal_get_title();
return $args;

- Leave 'Validator' as it is, at 'Basic Validation'
- Hit 'Update'

ressa’s picture

Better solution:

Arguments -- User: Uid
Action to take if argument is not present:
Provide default argument
User ID from URL
Validator options
Validator:
User
Allow both numeric UIDs and string username
Restrict user based on role
'customer'
Action to take if argument does not validate:
Display all values

blueearth’s picture

Hi,

I am just a newbie for views so perhaps I am missing something.

How do I get a view of all the nodes where the author of the nodes is the user that is logged?

What I need to do is get the query to show: "...Where node.uid = ***Current_User***" so it can show a table of all the user's nodes. How do I do this? Please help!

hixster’s picture

I want to print the author name as a field? Do i need a php snippet in a views custom field to look up the author name from the UID, or is there an easier way?

Nevermind, i found the field username!

Drupal Web Designers Surrey South East England www.lightflows.co.uk

clashar’s picture

ressa, doesn't work for me, cause I am as admin have also the role, so I could not be restricted to view the content. (I use node reference views)

ressa’s picture

Does it work if you leave out the restriction on user based on role?

clashar’s picture

ressa, firstly thank you for quick reply.
I think I put you in misunderstanding as your solution could not correspond to my issue, it is not technical, but logical.
I need that just author/owner of the referred content and not a role is available for filtering in argument.

clashar’s picture

my views works, when I have only filter by content type and "user current: yes", but that's not the author, and I still can't find a way to restrict author.

If I use your solution without restriction on role, then the result is empty, devel shows "No query was run."
When I check "User ID from URL" new box appears "Default argument: ", maybe I should provide smth here?

solution from manop didn't work for me neither, also no query is run and empty result.

ressa’s picture

Perhaps adding a Relationship might give you some more fields to use for filtering? Other than that I am not sure how to do it, sorry.

clashar’s picture

ressa, it's hours that I try to play with filter, relationships, arguments, but still no success.
Anyway, thank you for trying to help me ))

clashar’s picture

for those who will be interesting in my issue, I created it new one here: #946236: problem filtering by node's author (argument "User: uid", default "User ID from URL" or other), not yet solved, but I hope will be.

crossmedia’s picture

Could you please explain me more in details what you want to achieve?

if you want to get all ( anything ) created by or owned by logged in user, i would suggest you to create a view and add a Global PHP filter under Filters option.

By clicking Global PHP you will have several options, only you need to choose "SQL FILTER CODE" and paste the following php code.

global $user;
return "users.name IN (SELECT columnname FROM {tablename} WHERE uid = ".$user->uid.")";

Please do not include and closing while executing above lines of code in "SQL FILTER CODE"

The above code will return data only created by logged in user. Please correct me if i am wrong.