You are here

function advanced_forum_links_alter in Advanced Forum 7.2

Own link alteration implementation because there are no hook_link nor hook_link_alter in D7.

Name changed intentionally to avoid confusion with hook_link_alter!

2 calls to advanced_forum_links_alter()
advanced_forum_comment_view in ./advanced_forum.module
Implements hook_comment_view().
advanced_forum_node_view in ./advanced_forum.module
Implements hook_node_view().

File

./advanced_forum.module, line 348
Enables the look and feel of other popular forum software.

Code

function advanced_forum_links_alter(&$object, $view_mode, $object_type = 'node') {

  // Don't alter anything if in preview mode.
  if (!empty($object->in_preview)) {
    return;
  }
  if (!advanced_forum_is_styled($object, $view_mode == 'teaser', $object_type)) {
    return;
  }
  if (!empty($object->content['links']['comment'])) {
    $comment_links = $object->content['links']['comment'];
    $links = empty($comment_links['#links']) ? array() : $comment_links['#links'];
  }
  else {
    $comment_links = array();
    $links = array();
  }
  if ($object_type == 'node') {
    $node = $object;

    // Add edit / delete links to the node links to match replies.
    if (node_access('update', $node)) {
      $links['post-edit'] = array(
        'title' => t('edit'),
        'href' => 'node/' . $node->nid . '/edit',
        'query' => drupal_get_destination(),
      );
    }
    if (node_access('delete', $node)) {
      $links['post-delete'] = array(
        'title' => t('delete'),
        'href' => 'node/' . $node->nid . '/delete',
      );
    }
  }

  // Change first post from "add comment" to "reply" if it isn't already.
  if (!empty($links['comment-add'])) {
    $links['comment-add']['title'] = t('reply');
    $links['comment-add']['href'] = "comment/reply/{$node->nid}";
  }

  // List the keys we are interested in.
  $affected_keys = array(
    'post-edit',
    'comment-edit',
    'post-delete',
    'comment-delete',
    'quote',
    'comment-add',
    'comment-reply',
  );

  // Add extra span tags for image replacement.
  foreach ($links as $key => $link) {
    if (in_array($key, $affected_keys)) {
      $links[$key]['attributes']['class'][] = "af-button-small";
      $links[$key]['title'] = '<span>' . $links[$key]['title'] . '</span>';
      $links[$key]['html'] = TRUE;
    }
  }

  // Put the links in a consistent order.
  foreach ($affected_keys as $key) {
    if (isset($links[$key])) {
      $temp = $links[$key];
      unset($links[$key]);
      $links[$key] = $temp;
    }
  }

  // We want to put comment links last.
  unset($object->content['links']['comment']);
  $object->content['links']['comment'] = $comment_links;

  // Put links back.
  $object->content['links']['comment']['#links'] = $links;
}