In one installation of ours, we are using "favorites" as (also) a way to determine how a content has been "liked". So far, so good. The only issue was that now a person SHOULD NOT vote its own nodes as favorite. I simply added a "create favorites on own nodes" permission. I hope you like it

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kbahey’s picture

Status: Active » Needs work

I don't like this piece of code. It is very complex and will be a maintenance nightmare.

+      if (user_access(FAVORITE_NODES_PERM_ADD) AND
+          (!$user->uid OR $user->uid != $node->uid OR ($user->uid == $node->uid AND user_access (FAVORITE_NODES_PERM_ADD_OWN)))) {

It has to be more clear with comments. For example:

if (....) {
  if (....) {
     // something
  }
  else {
    // something
  }
}

It has to be a separate function (e.g. function _favorite_node_can_add()) Also use && and || as per code guidelines.

flexer’s picture

FileSize
1.83 KB

"Refactoring" the code as per your suggestions, I found that using permission doesn't work (the user 1 bypasses that check). I moved the option from being a permission to a setting. Patch attached.