I have created a view to show all the latest comments on my site, pretty much like the comments_recent view, but using comment row style instead of field row style.

Everything works so far. I get the list of comments sorted by post date correctly on the url I chose (say, /comments), but it looks to me as if Views is incorrectly pulling its own view path instead of the comment's post path to build the permalink in the comment url.

In other words, in a "real life" example, my comments show as:

href="/comments#comment-3"

... instead of ...

href="/entries/this-is-the-node#comment-3"

... which renders those links unusable and makes them point to the view itself.

I have checked and those are exactly the links that Drupal is sending to the browser. The first one is from the "non-working" view and the second one is taken directly from the node's page. So it cannot be the code in comment.tpl.php. I switched themes to also see all behave the same.

Furthermore (and I think this is important) I created a RSS feed display in the same view, and it works as expected (i.e. if I click on the comment titles in the feed, those take me to the original comment, in the original node. I'm using the same Comment:Node Relationship for both.

That leads me to believe that Views in considering the "views' comment display node" instead of the "comment parent node" (forgive me if those concepts are wrong, but that's how I'd describe this behaviour) to build up the full comment url.

Comments

frames’s picture

By the way, here's the exported view, just in case it helps:

$view = new view;
$view->name = 'comentarios';
$view->description = 'Comentarios';
$view->tag = 'comentarios';
$view->view_php = '';
$view->base_table = 'comments';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Valores por defecto', 'default');
$handler->override_option('relationships', array(
  'nid' => array(
    'label' => 'Nodo',
    'required' => 1,
    'id' => 'nid',
    'table' => 'comments',
    'field' => 'nid',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'timestamp' => array(
    'order' => 'DESC',
    'granularity' => 'second',
    'id' => 'timestamp',
    'table' => 'comments',
    'field' => 'timestamp',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('title', 'Índice de comentarios');
$handler->override_option('use_pager', '1');
$handler->override_option('style_options', NULL);
$handler->override_option('row_plugin', 'comment');
$handler->override_option('row_options', array(
  'links' => 1,
));
$handler = $view->new_display('page', 'Página', 'page_1');
$handler->override_option('path', 'coments');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));
$handler = $view->new_display('feed', 'Feed', 'feed_1');
$handler->override_option('title', 'Últimos comentarios');
$handler->override_option('style_plugin', 'rss');
$handler->override_option('style_options', array(
  'mission_description' => 0,
  'description' => 'Últimos comentarios publicados',
));
$handler->override_option('row_plugin', 'comment_rss');
$handler->override_option('row_options', array());
$handler->override_option('path', 'comments/rss');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));
$handler->override_option('displays', array());
$handler->override_option('sitename_title', 0);
frames’s picture

Version: 6.x-2.2 » 6.x-2.3

Upgraded to 6.x-2.3. Same behaviour.

Further testing has confirmed that this happens only in page displays, only if using node as the row style (does not happen with fields for row style or in feed displays).

Thanks

varkenshand’s picture

Same here

The path name of comment titles is example.com/25#comment, instead of example.com/node/25#comment.
The view as simple link is OK, btw. So I made a temporary workaround using this one.

frames’s picture

"The view as simple link is OK, btw. So I made a temporary workaround using this one."

Can you explain what do you mean by that, varkenshand? And what was the workaround?

Cheers

PS: I have tried to identify the error by having a look at the code. I was not clever enough to find it, though.
:-(

varkenshand’s picture

Never mind, this one seems a better solution:
http://drupal.org/node/369076

frames’s picture

Yeah, well, I saw that one already, but my understanding is that fix is only valid for field row styles.

This bug is happening in comment row styles used in page displays. Comment row styles actually work in feeds!

The fix must be quite similar to the one you point out, but my poor coding skills (none) have not allowed me to find anything relevant (I tried, though).
:-(

frames’s picture

Mmm ... another clue just recapping a bit.

In my HTML output I can find something like this:

<h3><a href="/comentarios#comment-5" class="active">Re: Why Drupal</a></h3>

Notice the "/comentarios" in front of the comment link (in bold). "comentarios" is the page url in my view (i.e. the page to display comments).

So the "/node" bit is actually been included (it would be something like <h3><a href="#comment-5" class="active"> otherwise), but the problem is, the current page node info is being inserted, instead of the original comment node info.

Do you think this could not be related to views but to Drupal core code? Maybe I forgot to add any extra info in my View?

frames’s picture

Just in case, I also tried adding a Comment: Node relationship, just in case it was needed to build the full url (it was not needed in feeds). As expected, does not work.

merlinofchaos’s picture

Ok, the problem is that the comment output theming, in Drupal, actually isn't using a link it all; it's just an anchor tag, so it's always assuming it will be on this page.

The path is set in http://api.drupal.org/api/function/template_preprocess_comment/6 where it uses $_GET['q'].

I'm torn on whether or not Views should be modifying this behavior or what.

You can work around this by implementing THEMENAME_preprocess_comment and changing the value of $title and using a proper URL.

naught101’s picture

Subscribing

merlinofchaos: ideally, it would be good to be able to choose either option (ie. output title link as link+anchor, or just anchor), but if that complicates things, then specifically for the comment row style, link+anchor is surely the sane default (ignoring the fact that's it's not the "proper" drupal way..)

frames’s picture

I'm sorry about the delay, merlinofchaos, but I have been checking this a few times and can't see that Drupal is using only an anchor to point to the comment.

This is actually working fine and outputting the full URL path (with or without the server name) in [a] the node page itself, [b] a Block display in the same view (using fields row style, had to use field "id" instead of View link, probably not related), [c] a Feed display in the same view (using a RSS feed Style) with the same deafault values. But not in the Page display for that view (obviously using a Comment row style).

Being totally blind to php code, I could only look at the output for these in my browser:

This is what I see for the feed (right):

    <title>Primer comentario</title>
***    <link>http://test.server.com/entradas/1/primera-entrada#comment-1</link>
    <description>Here goes the content.</description>
     <pubDate>Sat, 02 Jan 2010 16:48:00 +0000</pubDate>
 <dc:creator>Author</dc:creator>

This is what the actual node displays (right):

<div class="comment comment-published odd">

  <div class="clear-block">
      <span class="submitted">Sáb, 01/02/2010 - 17:48 — <a href="/usuarios/author" title="Ver perfil del usuario.">Author</a></span>
 
***    <h3><a href="/entradas/1/primera-entrada#comment-1" class="active">Primer comentario</a></h3>

    <div class="content">
      <p>Here goes the content.</p>
          </div>
  </div>

      <div class="links"><ul class="links"><li class="comment_delete first"><a href="/comment/delete/1">eliminar</a></li>

<li class="comment_edit"><a href="/comment/edit/1">editar</a></li>
<li class="comment_reply last"><a href="/comment/reply/1/1">responder</a></li>
</ul></div>
  </div>

And this is what I get in the page (wrong):

      <div class="view-content">
        <div class="views-row views-row-1 views-row-odd views-row-first">
    <a id="comment-1"></a>
<code>
<div class="comment comment-published odd">

  <div class="clear-block">
      <span class="submitted">Sáb, 01/02/2010 - 17:48 — <a href="/users/author" title="Ver perfil del usuario.">Author</a></span>
    
***    <h3><a href="/comentarios#comment-1" class="active">First comment</a></h3>

    <div class="content">
      <p>Here goes the content.</p>

          </div>
  </div>

      <div class="links"><ul class="links"><li class="comment_delete first"><a href="/comment/delete/1">eliminar</a></li>
<li class="comment_edit"><a href="/comment/edit/1">editar</a></li>
<li class="comment_reply last"><a href="/comment/reply/1/1">responder</a></li>
</ul></div>
  </div>
  </div>

I have marked with three stars (***) the important bits.

Excuse me if I got it wrong, but from that I'd say there's something missing in the Comment Row style.

merlinofchaos’s picture

I linked to the code where this happens. If you "can't see where htis is happening" then CLICK ON THE LINK AND READ THE CODE.

If you can't read the code, then get someone who can before you try to argue with me about what the code is doing. It's a waste of my time and yorus.

merlinofchaos’s picture

Just a note: comment RSS feed is not using that code, it is completely different piece of code, so it's irrelevant.

merlinofchaos’s picture

Oh and for further proof:

Let's say you have a node with id of 1 that has comments:

Visit /node/1 -- view source, search for #comment-

Now visit /node/1/arglebarglefoof -- view source, search for #comment-

esmerel’s picture

Status: Active » Closed (fixed)
naught101’s picture

Status: Closed (fixed) » Postponed

Why close this? It's not fixed, as far as I am aware. Next time I get bugged by it, I'll write up a patch.

dawehner’s picture

Noone did anything in longer then 6months. There is not even a patch.

merlinofchaos’s picture

This is closed because the code that's doing this is not in Views, and a workaround is provided.

dawehner’s picture

Status: Postponed » Closed (fixed)

.