Hi. advanced_forum_preprocess_comment.inc line: 82

$uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
shoudn't it looks like
$uri['options'] = array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
without + ?

Also, I need an advice. I want permalinks in my comments to looks exactly like in AD - I have been used this code:

function YOURTHEME_preprocess_comment(&$vars) {

  $posts_per_page = variable_get('comment_default_per_page_' . $vars['node']->type, 50);

  $page_number = !empty($_GET['page']) ? $_GET['page'] : 0;
  if (!$page_number) {
    $page_number = 0;
  }

  $linktext = '#' . (($page_number * $posts_per_page) + $vars['id']);

  $vars['comment']->uri['options'] = array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
  $vars['permalink'] = l($linktext, $vars['comment']->uri['path'], $vars['comment']->uri['options']);
}

but after update to drupal 7.12 it's not working anymore (permalink link is set to my homepage instead of comment)... Somebody know why ? How to fix it ? THX.

Comments

batigol’s picture

anybody ?

troky’s picture

Status: Active » Postponed (maintainer needs more info)

$uri['options'] is not necessarily empty so + operator is there to create array union.

Why don't you copy part of code from advanced_forum_preprocess_comment.inc and adjust it as you like?

for example:


  $linktext = '#' . (($page_number * $posts_per_page) + $vars['id']);

  $vars['comment']->uri = entity_uri('comment', $comment);
  $vars['comment']->uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
  $vars['permalink'] = l($linktext, $uri['path'], $uri['options']);

batigol’s picture

Ohh I do understand. I don't know php so I thought that + is an typo error (without it, code I used - from first post, in template.php works). Honestly I have no idea what should I do to display Permalink in comments like in AF. I would be glad If somebody can post it.

pwiniacki’s picture

I think that #numbers besides just Permalink link are a great idea! I would like to know the answer too. This is exactly the way it's is displayed here with comments on drupal.org

I can confirm that removing + from first post will give you Permalinks as a #numbers but to link to a comment is wrong.

kelutrab11’s picture

After drupal update code

function YOURTHEME_preprocess_comment(&$vars) {

  $posts_per_page = variable_get('comment_default_per_page_' . $vars['node']->type, 50);

  $page_number = !empty($_GET['page']) ? $_GET['page'] : 0;
  if (!$page_number) {
    $page_number = 0;
  }

  $linktext = '#' . (($page_number * $posts_per_page) + $vars['id']);

  $vars['comment']->uri['options'] = array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
  $vars['permalink'] = l($linktext, $vars['comment']->uri['path'], $vars['comment']->uri['options']);
}

from stack overflow is not working anymore. When + is removed, like author said, code works partially. There are numbers but the link is wrong. Did any of you manage drupal 7.12 comments to work/look just like in AF? If yes, please let me know.

pwiniacki’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)
function YOURTHEME_preprocess_comment(&$variables){

  /* Easy links to the comment and parent node */
  $comment = $variables['comment'];
  $node = node_load($comment->nid);
  $variables['first_post'] = $node; 

  // Set the post ID for theming / targetting
  $variables['post_id'] = "post-$comment->cid";

  /* Linked post number */
  if (!isset($post_number)) {
    static $post_number = 0;
  }

  $posts_per_page = variable_get('comment_default_per_page_' . $node->type, 50);

  $page_number = !empty($_GET['page']) ? $_GET['page'] : 0;
  if (!$page_number) {
    $page_number = 0;
  }

  $post_number++;

  $linktext = '#' . (($page_number * $posts_per_page) + $post_number);

  // Permalink
  //  You can erase next 3 lines if you wish to use built-in Permalink.
  //  Template adjusted: $post_link -> $permalink
  $uri = entity_uri('comment', $comment);
  $uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
  $variables['permalink'] = l($linktext, $uri['path'], $uri['options']);
}

is working great (from http://drupal.stackexchange.com/questions/4679/how-do-i-change-the-perma...) !

[Edit: Changed to php tags for highlighting]

michelle’s picture

Issue summary: View changes

edit