0

I've this code who show the number of users who 'flagged me' (I'm using flag module)

$flag = flag_get_flag('poke');

if ($flag) {
  print "The number of people who voted for this proposal:";
  print $flag->get_count($user->uid);
}

I want to show a list of the user name instead.

Thanks for your help !

  • Where do you want to display these usernames? Is the Flag you're talking about a user Flag? Maybe you're looking for the Views module? You can easily create a View that displays all the users who flagged a certain user. – Jeroen Jan 30 '16 at 17:27
0

I don't know the particular flag api to get the usernames of flagged node. But it can be possible using custom implementation. Here is code

function get_usernames_flagged_node($entity_id, $flag_name) { //Supply node_id and flag_name
  $get_all_nodes_of_flagged = flag_get_flag_flagging_data($flag_name);
  $flagged_content_detail = array();
  $username = array();
  foreach($get_all_nodes_of_flagged as $get_all_nodes_of_flags) {
    $flagged_content_detail[] = $get_all_nodes_of_flags;
  }
  foreach($flagged_content_detail as $flag_content) {
    if($entity_id == $flag_content->entity_id) {
     $user=user_load($flag_content->uid);
     $username[]=$user->name;
    }
  }
  return $username;
}

It can be also possible using views and flag modules. For your reference see this page

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.