I have a node with a user reference field, and I'd like to show that user's information in a views block on that node. I think I made it more difficult since some of that info is saved as a node in a content profile. So I made a view with the fields I need, then tried to setup an argument with some php code and that is where I am stuck.

This first part is because I'm using pathauto:

$path = drupal_get_path_alias($_GET['q']);
$path = explode('/', $path);
if ($path[0] == 'listings' && $path[1] != '') {
  return $path[1];
}

I think my real problem is here, I'm not sure if I'm pulling the (up to 4) names off the current node correctly (field name is 'contact'), then how do I return it - tell views to only show the fields for these user names?

$node=node_load($path[1]);
foreach ($node->field_contact as $user){
  $user = user_load(array('uid' => $node->field_contact[0]['uid']));
}
$args[0] = key($user);

return $args;

I'm not surprised if this is completely wrong as this is my first attempt at an argument and my php skills are limited. Thanks in advance for any help.

Comments

metastate’s picture

Old issue but I worked on a similar scenario yesterday. Use case: You have a content type with CCK user reference field, you want to select one or more users on each node and then have these users appear in a Views generated block on the node page.

You need to create a node View (not a user View) with the following:

1) Filters: Add a filter for the content type. Add another filter for the user reference field you created - set this to "Is not empty (NULL)" so that the block will only appear if a node has a user referenced from it.

2) Argument: You want the block to be based on the node that is being viewed, so you will need an argument for that. Add a new argument based on Node Id. Under "Action to take if argument is not present" choose "Provide default argument" and then select "Node ID from URL". Leave everything else as is.

3) Relationship: Add a relationship based on the CCK user reference field you created. Name it and select "Require this relationship".

Once you have a relationship set up you can add user or profile fields that use that relationship. This will pull in info for the referenced users, instead of the node author.

As far as the block goes, use the block visibility settings in the blocks admin area to choose which pages you want it to appear/not appear on.

dawehner’s picture

Status: Active » Fixed

so this is fixed

Status: Fixed » Closed (fixed)

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

Yuri’s picture

Thanks! This worked for me perfectly, using a 'customer' user reference field to create a viewfield in the same node with customer data.

dhakshinait’s picture

Title: pass cck user reference field to views argument » pass cck user reference field to views argument(to display block in front page)
Status: Closed (fixed) » Active

hai. i have two content types such as " Gallery " and "Photos" . I have one node reference field in "photos" content type and its name is "gallery" denoting to "Gallery" content type.

By using views, i have to display "photo" nodes for particular "Gallery" node in front page of my site. i think i have to use views argument for this. but i don't know how to do it. please help me

iamjon’s picture

Status: Active » Closed (fixed)

dhakshinait,
before reopening an issue please take a look at the submission guidelines:
http://drupal.org/node/571990
It generally considered inappropriate to hijack an issue with our own completely unrelated issue.

Changing status.

msmithcti’s picture

Thanks for the clear and concise instructions metastate - you've saved me a lot of frustration!

Anonymous’s picture

I just wanted to say "THANK-YOU" @metastate! I know this may seem trivial to some drupal devs but this has helped me with yet another "aha" moment for views. Everytime I learn something like this I think, "views + drupal = awesomeness!"

curtispenner’s picture

This was EXACTLY what I needed. Thank you @metastate!

keti-1931’s picture

Version: 6.x-2.8 » 7.x-3.1

thanks a lot ,
this worked for me....