I have a Thumbs Up widget on a page (added through Panels). No matter how many people have voted, it always shows "0 users have voted." when the page loads. After clicking on the thumb and saving the vote, the correct number of votes is then displayed. Refresh the page, and it goes back to 0.

Settings: Average rating for both "Which rating should be displayed? " and "Which rating should be displayed when the user just voted?"

Note- I tried other widget types and have the same issue.

CommentFileSizeAuthor
#9 rate.png122.88 KBhanskuiters

Comments

jemisond’s picture

Issue summary: View changes
ir.ma3x’s picture

same problem here...

nelsonre’s picture

I think the problem occurs when the option "Use source translation" is checked.

ir.ma3x’s picture

thanks.
that worked for me :)

hanskuiters’s picture

Where do I find the option "Use source translation"?

cprofessionals’s picture

capono,

Go to admin/structure/rate, select your widget and down at the very bottom there is a Translation section. Uncheck the box. It worked for me! I am using version 1.7.

hanskuiters’s picture

Thanks CPro. I have 7.x-1.7. There is no version 2.

cprofessionals’s picture

Oops, I guess it was in anticipation of 2.0 (I think I had just read the project page). I made the changes in my earlier post. Thanks for a great module!

hanskuiters’s picture

StatusFileSize
new122.88 KB

I added a screendump of my settings. No language section here.

A.Kotov’s picture

it is interesting that at "teaser" it works good even with "Use source translation" ON
no $results coming on "full" page load.

cprofessionals’s picture

Weird, I thought I posted a response yesterday. Capono, If you enable the Content Translation Module (Part of Core) you will get the options that have been mentioned in #3. So I guess you have to enable the translation to disable it in this module to get the module to work right? Sounds odd, but that seems to be the case. Hopefully the Developers are watching.

hanskuiters’s picture

Found the setting, thanks.

LeoVe’s picture

Yep, unselect option "Use source translation" worked here to.

errand’s picture

#3 worked for me too, tnx!

dan kolbas’s picture

Issue:
So I ran into this issue as well. So when you have those modules enabled as mentioned above you get the option to check the box under your widget settings: "Use source translations".

The problem with this is that the tnid is 0 on any node that does not have a translation node already created. When a translation is created that value is filled out and otherwise 0 until then. So what your seeing is that you have users vote on that node and it saves the voting results, but it doesn't return any results because the node ID that it is looking up is 0. Basically there is a bug in the code. I have a solution, but there is a case that i am not 100% sure how to handle that someone could run into.

Problematic function:

function _rate_get_source_translation($entity_type, $entity_id) {
...
}

Below is what I would suggest doing to fix the issue for almost all cases.

Purposed code changes:

function _rate_get_source_translation($entity_type, $entity_id) {
  if ($entity_type == 'node' && module_exists('translation')) {
    if (arg(0) == 'node' && arg(1) == $entity_id) {
      // We are on the node page. Use node_load since the node is in static cache.
      $node = node_load($entity_id);
      // If tid exists use it, otherwise determine if your on the source node.
      if ($node->tnid > 0) {
        // Source nid has been stated already.
        $entity_id = $node->tnid;
      }
      else {
        // Get default set language.
        $default_lang = variable_get('language_default');
        if ($default_lang->language == $node->language) {
          // Current node is in the default language, use it.
          $entity_id = $node->nid;
        }
        else {
          // Can't determine source language nid at this time.
          // Not sure what to do in this case. You basically have the same issue.
         // This is most likely less common and will only happen if you let your users create content in other languages before the source language.
        }
      }
    }
    else {
      // We are not on the node page. Do not use node_load to prevent executing many useless queries.
      $tnid = db_select('node', 'n')->fields('n', array('tnid'))->condition('n.nid', $entity_id)->execute()->fetchField();
      if ($tnid) {
        $entity_id = $tnid;
      }
    }
  }
  return $entity_id;
}

The code that is important above is:

// We are on the node page. Use node_load since the node is in static cache.
      $node = node_load($entity_id);
      // If tid exists use it, otherwise determine if your on the source node.
      if ($node->tnid > 0) {
        // Source nid has been stated already.
        $entity_id = $node->tnid;
      }
      else {
        // Get default set language.
        $default_lang = variable_get('language_default');
        if ($default_lang->language == $node->language) {
          // Current node is in the default language, use it.
          $entity_id = $node->nid;
        }
        else {
          // Can't determine source language nid at this time.
          // Not sure what to do in this case. You basically have the same issue.
         // This is most likely less common and will only happen if you let your users create content in other languages before the source language.
        }
      }

I don't have time atm to build out a patch file atm, but I wanted to document this before I forgot.

ivnish’s picture

Status: Active » Closed (outdated)

Drupal 7 is EOL. Issue will be closed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.