I've installed this module on content types that I'm creating using panels. Is there any way I can insert the "add to favorites" link for appropriate nodes using a custom block as my node types don't display the content body (so I don't see the normal link)?

Thanks for any help.

Comments

asund’s picture

You might want to take a look at the contemplate module (content template)

Anyway, if you'd like to do it manually it's pretty simple.
The add to favorite url is http://www.yourdrupalpath.com/favorite_nodes/add/[node-id]

Jboo’s picture

Thanks paranaiv, that works great. I guess there could be a way to display the "add to favorites" link and then to show "remove from favorites" if the node has already been added using PHP?

Thanks again.

Liliplanet’s picture

Version: 5.x-1.2 » 5.x-1.3
Priority: Normal » Critical

Hi,

Also would like this function please.

Code to insert in custom node-profile.tpl.php with 'add this user to favorites' and if selected, 'remove this user from favorites'.

Most appreciated.
Lilian

kbahey’s picture

Priority: Critical » Normal
Status: Active » Closed (fixed)

Why are you marking an issue critical when it is a support request. Nothing in the code is broken!
Also, why are you straying off topic?

For adding a user, use something to convert users to nodes, like node profile, content profile, or bio and then you can users to favorite nodes.

To answer the general question, you can add this anywhere in a node*.tpl.php to add an add/remove link.

It is best if we convert this to a themeable function. Patches welcome.

  if ($page) {
    if (variable_get(FAVORITE_NODES_NODE_TYPE . $node->type, 0)) {
      if (user_access(FAVORITE_NODES_PERM_ADD)) {
        if (!_favorite_nodes_check($node->nid)) {
          print l('add to favorites', 'favorite_nodes/add/'. $node->nid);
        }
        else {
          if (user_access(FAVORITE_NODES_PERM_VIEW)) {
            print l('remove from favorites'), 'favorite_nodes/delete/'. $node->nid);
          }
        }
      }
    }
  }
Liliplanet’s picture

Status: Closed (fixed) » Active

Thank you for your reply. I've tried the above in my .tpl and constantly receive an error syntax error, unexpected ','

Then copied the code from contemplate as follows:

<?php print $node->links['favorite_nodes_add']['attributes']['class'] ?><?php print $node->links['favorite_nodes_add']['href'] ?>

and nothing shows ..

Would most appreciate the correct code and thank you for your help.
Lilian

kbahey’s picture

Status: Active » Fixed

Try this.

  if ($page) {
    if (variable_get(FAVORITE_NODES_NODE_TYPE . $node->type, 0)) {
      if (user_access(FAVORITE_NODES_PERM_ADD)) {
        if (!_favorite_nodes_check($node->nid)) {
          print l(t('add to favorites'), 'favorite_nodes/add/'. $node->nid);
        }
        else {
          if (user_access(FAVORITE_NODES_PERM_VIEW)) {
            print l(t('remove from favorites'), 'favorite_nodes/delete/'. $node->nid);
          }
        }
      }
    }
  }
gabriel.ferreira’s picture

Version: 5.x-1.3 » 6.x-1.x-dev

I am having the exactly same problem, except that i'm using drupal 6.x and those codes didn't work here.

gabriel.ferreira’s picture

Status: Fixed » Active
pisco23’s picture

subscribing - did anyone get this to work?

kolashanpan’s picture

I need this too, but for Drupal 5.x
Please help

Thanks Knud

codevoice’s picture

Subscribing, is this something that can be made to work in a panel?

EDIT: This basic idea worked in a custom panel:

if ( !_favorite_nodes_check(arg(1)) ) {
print l('add to favorites', 'favorite_nodes/add/'. arg(1));
} else {
print l('remove from favorites', 'favorite_nodes/delete/'. arg(1));
}

The problem in a panel is that the $node is not set when the panel code is processed (or rather, the variable isn't accessible at the time to the code), so using $node->nid doesn't work. The simple above example, however, does.