Hello,

i love this great module. :)
I have one, maybe minor, problem.
I want to place the flag link in a block on the right sidebar.
At first i read this guide:
http://drupal.org/node/295383

an so i thought i create a block with PHP but in did'nt work out.
When i put the link into the node-[content-type].tpl.php everything works fine, but i think it would be more flexible to put in into a block.

Has anyone an idea?

Stefan

Comments

quicksketch’s picture

Status: Active » Fixed

If you're putting code in a block, the $node variable does not exist, so you need to load it manually first.

if (($node == menu_get_item()) && isset($node->nid)) {
  // Put your link code in here.
}

I'm going to go ahead and mark this fixed since it's been 3 weeks since the issue was filed. Please reopen if you have further questions on this.

Status: Fixed » Closed (fixed)

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

rami.sedhom’s picture

Version: 6.x-1.1 » 6.x-2.0-beta2
Status: Closed (fixed) » Active
Issue tags: +JavaScript, +ie7, +block

I'm not sure if I should report this as new issue or report it here since it's related to the same topic.

Anyway, I have tried to place flag in a block using the below code:

//If in single node page
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
  //Load node to get nid
  $node = node_load(arg(1));
  //Print Flag link
  print flag_create_link('bookmarks', $node->nid); 
}

The block is working fine in FireFox in all ways but not working in IE7 when flag link type is "JavaScript toggle". The Flag text is being printed but not linked to anything. Any ideas how to resolve this?!

quicksketch’s picture

This probably isn't related to this issue unless the link only doesn't work when displayed in the block. You'll probably find that the link doesn't work anywhere, not just when it's displayed in the block. Check the page for JavaScript errors that may cause Flag's AJAX to fail.

quicksketch’s picture

Status: Active » Closed (fixed)
rami.sedhom’s picture

Sorry for late response but actually the link only doesn't work when displayed in the block. It's working fine when it's placed in links underneath the post and there's no javascript errors in the browser.

dercheffe’s picture

Issue tags: -JavaScript, -ie7

First I want say "Thanks!" for this very useful module.
A few weeks ago, I started to port my major Drupal project to D7. Now I would need a block, in which I can display the different flags as a link list in my first sidebar. Can anybody help me, how I can solve my problem?
Will there be a block provided by the module in the near future?

Thanks for your replies :)

Cya,

dercheffe

drupalreggie’s picture

Version: 6.x-2.0-beta2 » 6.x-2.0-beta6
Status: Closed (fixed) » Needs review

I'm using views to generate a block containing flag links relating to a node. I'm using the following code in a custom PHP field

//If in single node page
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
  //Load node to get nid
  $node = node_load(arg(1));
  //Print Flag link
  print flag_create_link('flag_name', $data->nid); 
}

But I do not see the flag text appear in the block...

Any suggestions?

drupalreggie’s picture

Status: Needs review » Active
drupalreggie’s picture

Status: Active » Fixed

got the above code to work OK, I had to set the relationship with the flag up in views.

Status: Fixed » Closed (fixed)

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

zilla’s picture

any idea how to modify that code snippet above for D7 so that i don't get the php error?

maked1sky’s picture

Friends if you get ERROR 404 or php error after confirm flag at views php fileds check VAILABLE VARIABLES
at PHP fields.
For me it works fine:
Output code
print flag_create_link('price_payment', $data->nid); // price_payment - name of my flag, $data->nid instead of $node->nid

mikemoretti’s picture

Issue summary: View changes

Actually, you already have the nid, it's arg(1). You don't even need to load the node. I used this code and it works like a charm:

//If in single node page
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
  //Print Flag link
  print flag_create_link('flag_name', arg(1));
}
Anonymous’s picture

This might be a bit late but will help someone for sure.

This is how to create a bookmark link in a block using views (Drupal 7 and 8):

  1. Create a custom Views using content and fields
  2. Go to Advanced -> Contextual Filters -> Add
  3. Search for ID and add it ... should be ID Content (NOT UUID)
  4. WHEN THE FILTER VALUE IS NOT AVAILABLE
  5. Tick -> Provide default value
  6. Type -> Content ID from URL
  7. WHEN THE FILTER VALUE IS NOT AVAILABLE
  8. Tick -> Specify validation criteria
  9. Validator select -> Content
  10. Multiple arguments -> Single ID
  11. Add -> RELATIONSHIPS (Advanced)
  12. Add -> Content flag
  13. Fields -> Add -> Flagging: Flag link

Have fun