4

Flag Friend Add Friend Link with views. Flag friends shows a link to add friend in my account page but i want to display this link on in a field for a view.

2

In views you have to go to advanced setting and in relationship you can add your flag.

flag

After that you will be able to add your field.

  • What I am looking for is a field that allows a one click to add friend? – Sun Rhythms Sep 19 '12 at 14:46
  • 2
    Ok I see it now... After adding the relation it gives me the option of the link... there is also a php way to do it as well... <?php $account = menu_get_object('user'); print flag_create_link('fools', $account->uid); ?> – Sun Rhythms Sep 19 '12 at 15:57
  • Yes after you add the relationship you have many fields available but i have actually a problem when the view is rendered, i don't know why. – Epok Sep 19 '12 at 16:00
  • It works fine for me with the javascript... What is your problem? – Sun Rhythms Sep 19 '12 at 17:24
  • I have Undefined offset: 0 in flag_friend_handler_field_links->render(), i never had this before but it's not really important. – Epok Sep 19 '12 at 17:59
1

If I understood you correctly you want to add flag link to the view (as a field).

Here is a video demonstrating it. Quoting from this:

  • Install the Views PHP module and enable it. This will allow you to embed php into a view cell.
  • Add a new nid/node id field to your View. Make sure to check the “Exclude from display” checkbox.
  • Rearrange your fields so that your hidden nid field is at the top of all fields. This is important. It needs to be “available” as an element to the custom php field we are about to add, and if it’s after, the custom php field won’t see it.
  • Add a new Global: PHP field. add the following code to the "Output Code" section of the field (in php): <?php print flag_create_link("the_machine_name_of_your_flag", $row->nid); ?>
  • Click the apply button
  • The "Views PHP" module is unnecessary for this. @Epok's answer should work with the latest versions of Views and Flags. The important step is to add the Relationship to the Flag first, then you'll be able to add a "Flags: Flag link" field. – thirdender Nov 4 '14 at 0:04

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.