1

I have a view that I am setting up that will be the view used to select users from a user reference field. I want to build the view so that it only allows the user to reference users that are referenced by a node that this node is referring to.

To Illustrate:

Node Type A => References different users with separate user reference fields (not multi-value fields)

Node Type B => References Node Type A, AND will only reference users that are currently referenced in Node Type A

So I am trying to provide an array of default arguments using PHP in Views. Here's what I have so far:

$node = node_load(arg(1));

if($node) {
$users = array(
'am' => $node->field_am_reference[0]['uid'],
'realtor' => $node->field_realtor_reference[0]['uid'],
);
  foreach($users as $user) { 
  return  $user;
   }

} 
else {
return FALSE;
}

The Node Type B form is embedded into Node Type A's node view in the .tpl file, so I am loading Node Type A's nid from the url...this is working, but I am only getting the first user reference ('am') field to show up in the checkbox list that is used for the user reference options for Node Type B's embedded form.

  • Figured it out... $node = node_load(arg(1)); if($node) { $user_args = array( $node->field_am_reference[0]['uid']. ','. $node->field_realtor_reference[0]['uid']. ','. $node->field_title_rep_reference[0]['uid']. ','. $node->uid ); foreach($user_args as $user){ return $user; } } else { return FALSE; } – user2014 Aug 16 '11 at 19:39
0

Okay...Here's the right way to do it. I was running into a problem with empty key values. I had to create the array out of the user reference fields I wanted, scrape any of the empty array keys

$node = node_load(arg(1));

if($node ) {
$user_args = array(
$node->uid,
$node->field_am_reference[0]['uid'],
$node->field_realtor_reference[0]['uid'],
$node->field_title_rep_reference[0]['uid']

);
//Remove empty array values and thier respective keys 
  $clean_args = array_filter($user_args, 'strlen'); 

//Take all of the array values and put them into a single key 
  $safe_args = implode(',' , $clean_args);

return $safe_args;
}



else  {

return FALSE;

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy