Please assign associative key to $links entry

olio - September 3, 2007 - 15:51
Project:Favorite Nodes
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi,
it would be kind if you could assign a specific key to the $links entry of the favorite nodes module ( '$links['favorite_node']' in the function favorite_nodes_link() ). This tiny change would be a huge help for everyone using e.g. hook_link_alter() to define conditions when and where this link should be displayed.
With this specific key I could use this function in a custom module e.g. to hide the 'add to favorite' link on the user's own nodes:

function linkchanger_link_alter(&$node, &$links){
global $user;
if($node->uid == $user->uid){
unset($links['favorite_node']);
}
}

At the moment, the key for the $links entry of favorite nodes is simply '0' and therefore could cause problems in case the order of the $links elements will change.

Thank you!

#1

olio - September 3, 2007 - 17:14

Instead of long explanation, this is how the function favorite_node_links() could look like after the changes I described in my previous post:

/**
* Implementation of hook_links().
*/
function favorite_nodes_link($type, $node = null, $teaser = false) {
  global $user;
  $links = array();
  if ($type == 'node' && !$teaser) {
    if (variable_get(FAVORITE_NODES_NODE_TYPE . $node->type, 0)) {
      if (user_access(FAVORITE_NODES_PERM_ADD)) {
        if (!_favorite_nodes_check($node->nid)) {
          $links['favorite_add'] = array('title' => t('add to favorites'), 'href' => 'favorite_nodes/add/'. $node->nid);
        } else {
          if (user_access(FAVORITE_NODES_PERM_VIEW)) {
            $links['favorite_exist'] = array('title' => t('in favorites'));
            $links['favorite_remove'] = array('title' => t('remove from favorites'), 'href' => 'favorite_nodes/delete/'. $node->nid);
          }
        }
      }
    }
  }
  return $links;
}

Now the links generated by the favorite node module could be easily called and manipulated to fit the specific needs of the user.
Thanks!

 
 

Drupal is a registered trademark of Dries Buytaert.