Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
add $uid argument to favorite_nodes_add($nid) function, for better flexibility
default will be the currently login user, but this function could be called with a different user.
this is the changed function: (sorry i didn't patch it)
<?php
/**
* Add a favorite node.
*/
function favorite_nodes_add($nid,$uid) {
if (empty($uid)) {
global $user;
}
else if {
$user = user_load('uid'=>$uid);
if (!$user->uid) {
return FALSE;
}
}
$node = node_load($nid);
if (!$node->nid) {
return FALSE;
}
db_query("DELETE FROM {favorite_nodes} WHERE nid = %d AND uid = %d", $nid, $user->uid);
db_query("INSERT INTO {favorite_nodes} (nid, uid, last) VALUES (%d, %d, %d)", $nid, $user->uid, time());
/**
* Invoke hook_favorite_nodes(), which has the following parameters:
* @param op
* The operation being performed. Can be either 'add' or 'delete'.
* @param node
* The node object being added or deleted.
*/
module_invoke_all('favorite_nodes', 'add', $node);
return TRUE;
}
?>