0

I have a node page of Project content type which contains a multiselect enitity reference field of user type called field_team. I also have a block created by my custom module which is displayed at Project type pages only. What i'm trying to achieve is to do smth like this:

if ($current_node->field_team contains $current_user->uid) {
$output = 'some_specific_content'; 
} else {
$output = 'you are not a team member of this project';
}

How can I check if currently viewed node contains current user in its reference field?
Will be very thankful for any help or advice.

0

Check following code:

global $user;
$team_members = array();
foreach($current_node->field_team['und'] as $team){
$team_members[] = $team['target_id'];
}

if (in_array($user->uid, $team_members)) {
$output = 'some_specific_content'; 
} else {
$output = 'you are not a team member of this project';
}
  • Replaced uid by target_id – Vishal Patil Mar 4 '15 at 9:14

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.