Download & Extend

Views integration for comment links

Project:Talk
Version:6.x-1.x-dev
Component:Documentation
Category:support request
Priority:normal
Assigned:a1tsal
Status:needs review

Issue Summary

So if you have added comment fields pointing to nodes with talk pages you will have noticed that they go to the main node page, rather than the comment page - which is pretty confusing, especially when you are clicking on a "new" comments link.

This patch fixes this by adding 2 additional comment field handlers that have correct handling for talk pages. Alternatively we could override the existing handlers, but I figured that that could cause problems if other modules happen to be doing the same thing. This is a Drupal 5.x patch, since that is what I needed, but the same approach should would fine with Drupal 6.x views too.

AttachmentSizeStatusTest resultOperations
views.patch2.53 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch views_37.patch.View details | Re-test

Comments

#1

Any chance you could update this for 6.x views?

#2

Any chance of making this work for Drupal 6.x/Views 2?

Additionally is there any other methods of fixing this issue and rewriting the links from the Recent Comments block to the correct comment location in the Talk tab?

-backdrifting

#3

You know, the way that Views 6.x-2.x works with the token rewriting stuff you can do most of this already by rewriting the output of the field... That's true as long as the content types in the view you are using all have talk enabled.

#4

True, but what to do with forum topics? I would not want to have a talk page for it.

Also, having added a [nid]/talk link to the proper field, how to specify the comment's anchor?

#5

To rewrite the field in Views 2.x did you just click on the rewrite checkbox for the comment title field and then just paste your token into the text box? So you added this:

[nid]/talk

Is that correct?

=backdrifting

#6

Hmmm ... I added this [nid]/talk to the comment title field in the text rewrite box but it's not working. Can anyone send instructions on how to rewrite the comments URLs to the Talk enabled ones using Views 2? What do I put into the Text box (under Rewrite output of this URL) and then what goes into the Link Path field?

-backdrifting

#7

I used "[nid]/talk" as an example, it really depends if you are using Pathauto, and how it is setup.

Anyway, I have to postpone using Talk, until I can also add the proper anchor to a given comment.

#8

The anchor is #comment-[cid]

#9

Wonderful. Thank you very much.

#10

vasudev - can you give a specific example of how you did this in Views? Can you send me a screenshot of your exact configuration in Views - how you did the actual rewrite using Tokens?

Thanks in advance.

-backdrifting

#11

bump, subscribing and wondering: when will this be available in version 6?

#12

Maybe this would best be done in custom_url_rewrite_outbound() instead? We could include a sample function in the README.txt, or define the function on a conditional basis / in a separate file.

#13

IMO this should be "won't fixed" based on the ability to do it in views 6.x-2.x. Or we could add docs about how to do it there.

#14

Docs would be good.

#15

I can't see how to make this work (with Views 2). I am getting substitution for the [subject] token but not for [nid] or [cid].

Has anyone actually made this work? If so, could you please explain a little bit more about how?

Thanks much!

#16

I made it work. Be sure that the order of the fields puts the nid/cid before the subject.

#17

OK, the thing I was missing was that you have to add Node:NID and Comment:ID Fields to the View, move them to the top of the Field list in the view, and mark them "Exclude from display". In the Title Field, set "Rewrite the output of this field" to "[subject]", turn on "Output this field as a link", and set the "Link path" to "node/[nid]/talk/#comment-[cid]".

It is now working for me. Thanks.

As far as I can tell, there is no documentation at all for "Rewrite the output of this field". I figured all this out based on http://drupal.org/node/518808 which describes a similar situation.

The solution does not seem obvious to me. I hope what I have written here will be useful to others. I will do my best to answer questions about how I got this working if the recipe above is still obscure.

#18

Version:5.x-1.3» 6.x-1.x-dev
Component:Code» Documentation
Category:feature request» support request
Status:needs review» needs work

Updating fields... This problem is in 6.x as well as 5.x, it is now a documentation issue not a code issue, and "needs work" rather than review because someone has to actually write the documentation :-( Maybe my last posting can be the basis for that. I am willing to write the text if someone can tell me where it should go and how to get it there. Currently there is no "documentation" link on either the module project page or on the admin page when installed.

#19

Great work, a1tsal - I think this should go in the README.txt that comes with the module.

#20

OK, I volunteer to write a new README.txt, and perhaps the project page can link to it for documentation.

There are several new features under active development (which I'm depending on for my own sites). Maybe those will converge pretty soon and there will be a new release that includes them? If so, I'll hold off until a release is near, so the documentation can cover them.

#375272: alternate path integration for D6 version
#751334: Option to use string different from "talk" in path
#444894: Add option to remove "View" and "Talk" tabs under node title

#21

Assigned to:Anonymous» a1tsal

Assigning to myself.

#22

I think you can go ahead with the changes without worrying about those three issues. They won't affect the nature of the task very much so it will still be good documentation even if those three issues get implemented.

Also, rather than linking to a new README.txt from the project page you can just add your text to the current README.txt and file a patch.

#23

Status:needs work» needs review

Right you are, these are separable issue.

Attached is a patch for the README.txt.

Could someone please try this recipe out, following it carefully point by point, to see if there is anything missing or wrong? It's actually a somewhat absurdly long series of steps, and it's possible that I've dropped something somewhere.

greggles, I was thinking that it would be good to link the project page to the current version of README.txt in CVS. Various other projects do this; it is a useful way to be able to read the documentation without having to download and unpack the module.

I don't have edit access to the project page, so I can't do that.

AttachmentSizeStatusTest resultOperations
TalkViewsDoc.patch2.57 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch TalkViewsDoc.patch.View details | Re-test

#24

Status:needs review» needs work

The last submitted patch, TalkViewsDoc.patch, failed testing.

#25

With regard to the patch failure -- this is the first time I have done a Drupal patch -- Maybe it was because I used absolute paths rather than relative ones?

Here, for the sake of anyone who doesn't want to mess with the patch file, is the documentation as plain text:

MAKING A "RECENT COMMENTS" BLOCK
================================
The Talk module does not work correctly with the core (built-in)
"Recent comments" block. However, you can create a replacement using
the Token and Views modules.

First, install and enable those modules (if they are not already
available on your site).

Then you can create the "Recent comments" block with Admin > Site
Building > Views > Add. This involves quite a large number of steps,
but all of them require only clicking buttons and filling in forms.

Set: View name: "recent_comments"
View description: "Recent comments"
View tag: leave blank
View type: Comment
Press Next.

Then do the following sequences of operations:

Relationships > Comment:Node > Add > Update

Fields > + > Node:Nid > Add > Exclude from display > Update
Fields > + > Comment:ID > Add > Exclude from display > Update
Fields > + > Comment:Title > Add
Label: set it to be blank
Check Rewrite the output of this field and set it to "[subject]"
Output this field as a link: "node/[nid]/talk/#comment-[cid]"
turn off "Link this field to its comment"
Update
Fields > + > Comment:Post date > Add
Label: set it to be blank
Date format: "Time ago (with "ago" appended)"
Update

Sort criteria > + > Comment:Post date > Add
Sort order: Descending
Update

Filters > + > Node:Published or admin > Add > Update
Filters > + > Comment:In moderation > Add > Moderated > No > Update

In the short left-hand column headed "Defaults", change the selector
to "Block" and do "Add display".
The "Block" display should now be selected in that column.
In "Basic settings", change the title to "Recent comments". Update.
Change "Style" to "HTML list". Update.

Save the view.

Now go to Admin > Site Building > Blocks. Select your theme.
In the disabled block list, you should find "recent_comments:Block".
Assign it to a region.
Assign the core "Recent comments" block to "".
Do "Save blocks".

You should now see a "Recent comments" block in the region you
selected. Test it by clicking on one of them, and verify that it
takes you to the comment on the Talk page correctly.

#26

Revised patch using relative path.

AttachmentSizeStatusTest resultOperations
TalkViewsDoc2.patch2.5 KBIdlePASSED: [[SimpleTest]]: [MySQL] 26 pass(es).View details | Re-test

#27

Status:needs work» needs review

Hmm, maybe I need to change the status to "needs review" in order to get the testing bot to wake up?

#28

I have the same issue as the OP. So what I gather from this is that the solution is a workaround using the views field rewrite feature, correct? I assume I can do this with View 3.x in use on my site using "node/[nid]/talk/#comment-[cid]" as the rewrite link. But won't this create a problem since my views include several node types, some of which use talk and some that do not use talk?

I've really been wanting to fix this problem on my site, because I love using this module, so any help that intrinsically fixes this views issue will make things operate much better.

#29

I don't know anything about Views 3.x, I'm afraid. (That is in alpha; I am using the released version, 2.x.)

> won't this create a problem since my views include several node types, some of which use talk and some that do not use talk?

I am not totally sure I understand your question...

The procedure here creates a new view. It won't interfere with any other views you may have created before.

If you have more than one node type, some of which have Talk enabled and some not, then you won't be able to have a single view that shows comments on all of them. (At least, not using this recipe; there may be a way to do it; a Views wizard might be able to help.) You could have different views for comments on different node types.

If you have to have a single view for all comments (some Talk and some not), I would suggest going with the approach suggested in #12: using custom_url_rewrite.

#30

@a1tsal

Your last comment applies to my situation, I have several single views that have links to comments of various node types (some using talk and some not). The approach in #12 doesn't appear to be something I am capable of right now, a code rewrite (if I am understanding that solution correctly). Since the "rewrite field output" proposed here doesn't solve my views problem, should I open a separate issue or keep following here?

#31

It is not exactly a code re-write; custom_url_rewrite is a sort of extra thing you can add on, to change the way paths work. It does require writing PHP code, though.

I am not sure how best to proceed here, in terms of issue tracking.

Greggles, could you give your opinion about whether it is best to commit this and declare the problem half-solved and open a new issue for the use case of brisath #30; or better to try to develop a new solution here that addresses that case?

I guess I would favor the former -- this addresses the probably typical use-case, and is fairly cheap & easy; someone would need to write actual code to address the #30 use case, and who knows when that will happen.

#32

Hmm. As an alternative to the (somewhat ridiculously long) series of operations needed to create the view, one could do it in one step via the Views "import" functionality.

Maybe it would be better to document that?

The gibberish to import, for the record, is:

$view = new view;
$view->name = 'recent_comments';
$view->description = 'Recent comments';
$view->tag = 'undefined';
$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', 'Defaults', 'default');
$handler->override_option('relationships', array(
'nid' => array(
'label' => 'Node',
'required' => 0,
'id' => 'nid',
'table' => 'comments',
'field' => 'nid',
'relationship' => 'none',
),
));
$handler->override_option('fields', array(
'nid' => array(
'label' => 'Nid',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 0,
'exclude' => 1,
'id' => 'nid',
'table' => 'node',
'field' => 'nid',
'relationship' => 'nid',
),
'cid' => array(
'label' => 'ID',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_comment' => 1,
'exclude' => 1,
'id' => 'cid',
'table' => 'comments',
'field' => 'cid',
'relationship' => 'none',
),
'subject' => array(
'label' => '',
'alter' => array(
'alter_text' => 1,
'text' => '[subject]',
'make_link' => 1,
'path' => 'node/[nid]/talk/#comment-[cid]',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_comment' => 0,
'exclude' => 0,
'id' => 'subject',
'table' => 'comments',
'field' => 'subject',
'relationship' => 'none',
),
'timestamp' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'date_format' => 'time ago',
'custom_date_format' => '',
'exclude' => 0,
'id' => 'timestamp',
'table' => 'comments',
'field' => 'timestamp',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'timestamp' => array(
'order' => 'DESC',
'granularity' => 'second',
'id' => 'timestamp',
'table' => 'comments',
'field' => 'timestamp',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'status_extra' => array(
'operator' => '=',
'value' => '',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status_extra',
'table' => 'node',
'field' => 'status_extra',
'relationship' => 'nid',
),
'status' => array(
'operator' => '=',
'value' => '0',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'comments',
'field' => 'status',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('title', 'Recent comments');
$handler->override_option('use_more', 1);
$handler->override_option('use_more_always', 0);
$handler->override_option('use_more_text', 'more comments . . .');
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'grouping' => '',
'type' => 'ul',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);