Download & Extend

Add widget to node/comment $links

Project:Rate
Version:7.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

Hello, I've just added this module and think it's perfect for my needs. I just wanted something to act as a "like" button in Facebook, and this does the job with thumb up.

My coding skills aren't that great, and was wondering if I could get some tips on how to integrate it with advanced forums so that the thumbs up widget appears at the foot of the post near the reply buttons, and not the body (is it does if you select 'below content'). And that you can also view the rating for a topic from the forum category display next to each post.

Thanks, I know it's asking a bit but I think it would help a lot of basic needs of some noobs like me.

Comments

#1

I'm really trying to solve this on my own, but I honestly am just not that good with coding yet. I noticed in my forum-topic-list.tpl.php file there is a line which prints something like views here.

<?php
print $topic->views_count;
?>

I've tried changing it to

<?php
print $topic->rate_thumbUp['#value'];
?>

But it doesn't seem to be working out. Am I missing something? That's one part of what I'm trying to do (get the thumb count in line with the topic in forum view), the other is get the rating widget to appear next to reply buttons and such.

#2

That should work in your template. Is the name "thumbUp" correct? You can check that at node/123/devel/render when you have the devel module installed. And make sure that the display setting in the widget configuration is set to "Do not add automatically".

When you have that working, you can use the following code to get the widget by the node id, so you can use it anywhere you like:

<?php
$node
= node_load($nid);
node_invoke_nodeapi($node, 'view');
print
$topic->rate_thumbUp['#value'];
?>

#3

Thanks so much for the reply mauritsl. I made the changes but...

Unfortunately it still doesn't work. Changed the file, made sure it was uploaded to the correct theme I'm using... still no luck. I installed devel and went to the topic list node with /devel/render appended... but not sure what I was supposed to see. Maybe I have some configurations wrong. Here is the code I have. Is there something I'm supposed to define first, or are the variables for rate usable by any node freely?

<?php foreach ($topics as $topic): ?>
    <tr class="<?php print $topic->zebra;?>">
      <td class="title">
      <div class="icon"><?php print $topic->icon; ?></div>
      <?php print $topic->title; ?>
      <div class="created"><?php print $topic->created; ?></div>
      </td>
    <?php if ($topic->moved): ?>
      <td colspan="3"><?php print $topic->message; ?></td>
    <?php else: ?>
      <td class="replies">
        <?php print $topic->num_comments; ?>
        <?php if ($topic->new_replies): ?>
          <br />
          <a href="<?php print $topic->new_url; ?>"><?php print $topic->new_text; ?></a>
        <?php endif; ?>
      </td>
      <td class="rating"><?php print $topic->rate_thumbup['#value']; ?></td>
      <td class="views"><?php print $topic->views_count; ?></td>
      <td class="last-reply"><?php print $topic->last_reply; ?></td>
    <?php endif; ?>
    </tr>
  <?php endforeach; ?>
  </tbody>
</table>

#4

Just adding my two cents here. I don't use forums but to my knowledge forums use comments do they not?

If thats the case to print the voting widget manually in comments use $comment->rate_NAMEOFWIDGET.

So maybe you can try $topic->rate_thumbUp.

Also thanks mauritsl for this module. I do hope it becomes the main voting module for Drupal.

#5

Walker,

They already do add themselves to comments when the option is selected in admin. What I'm trying to do is custom theme it so that it's on a specific place in the comment field (preferably right next to the reply, delete, edit options. When it's in the comment body, it almost seems as if it's part of the user's own writing. I know if you are not using a border style forum theme it probably doesn't seem that way, but unfortunately mine is.

I too love this module. It's the closest thing to a simple "like" feature in Facebook.

#6

I don't add the widget to comments automatically, I like to have more control over where it is placed. Thus I use $comment->rate_NAMEOFWIDGET in the comment.tpl. I figured forum threads would be the same thing. Sorry it didn't work.

BTW, if your looking for "Like" type feature flag might be best suited for you...

#7

Title:Forum integration» Add widget to node/comment $links

You're not talking about integrating it with advanced forum. You're talking about adding the widget to comment $links. This must be done via hook_link(). The "reply, delete, edit" links are part of the comment $links array.

#8

Version:6.x-1.0-beta5» 6.x-1.0
Component:Miscellaneous» Code
Category:support request» feature request

I also needed my widget to be in node/comment links, and because I love this module so much I've created a patch to add an option to display widgets in node/comment links.

I've tested it and everything works without problem, so if someone else could test it out then the maintainer can add this into the next release.

Instructions:
After applying the patch, you'll see a new option called "Links" under the "Display Settings" fieldset on the "Edit widget" settings page.

AttachmentSize
rate-add_widget_to_node_comment_links.patch 2.79 KB

#9

I'm very sorry, but the last patch had a mistake in it. This one should be correct.

AttachmentSize
rate-add_widget_to_node_comment_links-947516-9.patch 2.83 KB

#10

Status:active» needs work

Patch doesn't apply but the code is sound. Please reroll and mark "needs review".

#11

thanks all!

#12

Status:needs work» patch (to be ported)

Commited to git for D6.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Needs to be ported to D7.

#13

Version:6.x-1.0» 7.x-1.x-dev
Status:patch (to be ported)» needs review

Working on the Drupal Commons sprint at SAND Camp today. We needed the rate widget in node links and ported it to D7.

The patch adds functionality and a display option to the admin form for displaying the widget in the node links.

My IDE is setup to remove trailing white space, which is all the empty fields. That is what all the lines that don't appear to be changed in the patch are.

AttachmentSize
widget_to_link_d7-947516-13.patch 10.77 KB

#14

Status:needs review» needs work

After some testing #13 wasn't displaying the Rate module node links in AdaptiveTheme but did display in Garldand. I believe we want to set:

<?php
$node
->content['links']['rate']['#theme'] = 'links';
$node->content['links']['rate']['#attributes'] = array('class' => array('links', 'inline'));
?>

Similar to how other modules such as Flag do when placing node links.

#15

Status:needs work» needs review

Re-roll per #14.

AttachmentSize
947516-rate-node-links-15.patch 5.88 KB

#16

Reviewing the patch in #15, discovered that the new display option wasn't included in the admin screen.

Attached patch includes #15 and addition of RATE_DISPLAY_IN_LINKS to rate.admin.inc options.

Just now noticed the prior D6 patch from #9 called this item simply "Links" where I settled on "In the links section"... truthfully, both are pretty confusing for a site builder. Naming things is hard.

AttachmentSize
947516-rate-node-links-16.patch 1.7 KB
nobody click here