The tokens and data selectors below return no values (tested using Rules and Automatic Entity Labels). The token table description says the token may be appended with user_rating or average_rating.

[node:field-fivestar:user_rating] or %node:field-fivestar:user_rating
[node:field-fivestar:average_rating] or %node:field-fivestar:average_rating

Using these tokens or data selectors in all configurations I could conceive of returned no data or error messages. It is curious that these selectors are only available in Rules when the allowed data selector type is text. They are not available for integer or decimal selections.

Setup:
- Drupal 7.18
- Fivestar7.x-2.0-alpha2+5-dev (+entity reference patch)

Comments

LeviThomason’s picture

Issue summary: View changes

typo corrections

whiteph’s picture

Issue summary: View changes

Please test with 7.x-2.1 release and report back, as there have been a lot of fixes applied since then.

jetsonjohn’s picture

Token is not working in Display suite also.

Steps to reproduce:
1. Created a custom field using display suite
2. Added the token in the code
3. Rating is not displaying and also not showing an error

Notice: Undefined index: rating in entity_metadata_field_property_get() (line 438 of sites/all/modules/contrib/entity/modules/callbacks.inc).

This is also the same issue faced to Louis Bob
https://www.drupal.org/node/1741524

haunted’s picture

Hello, i have the same problem, The scenario is the one described here https://www.drupal.org/node/1308114 and i want share to facebook the vote that single users gives to a content, that is the fivestar field in the comment.

The two tokens [comment_fivestar_field:user_rating] and [comment_fivestar_field:average_rating] don't produce any otput.

If i use just [comment_fivestar_field] then it works but the output is like (if for example the rating is 4/5):

4 Average: 4 (1 vote)

While it should be just "4", or "user rating 4", since there is no average value in comment's fivestar field but only a single user's vote.

Thanks.

bluesman2014’s picture

I have the same issue

stalecheerios’s picture

Same issue - following.

emmene-moi’s picture

StatusFileSize
new932 bytes

Proposed patch

kobee’s picture

Same issue, the token is not returning anything on Metatag

energee’s picture

This is still broken, tokens return empty values. Patch above does not correct the issue.

dbt102’s picture

Status: Active » Needs work
rot3r1’s picture

is there any Update or fix?

awd studio’s picture

Here is my solution.

Patch also provide new property with fivestar rating - "rating_fivestar" (e.g. "4.5, 3.2, 5" etc.). It is useful for using in Schema.org properties like http://schema.org/AggregateRating.

awd studio’s picture

Status: Needs work » Needs review

The last submitted patch, 6: fivestar-wrong-property-data-1881874-0.patch, failed testing. View results

castor-designs’s picture

Apparantly that patch is now part of module code? Because I have these lines in my initial file:

/**
 * Callback to alter the property info of fivestar fields.
 */
function fivestar_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) {
  $name = $field['field_name'];
  $property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name];

  $property['property info'] = array(
    'average_rating' => array(
      'label' => t('Average Rating'),
      'type' => 'text',
      'microdata' => TRUE,
    ),
    'user_rating' => array(
      'label' => t('User\'s Rating'),
      'type' => 'text',
      'microdata' => TRUE,
    ),
    'rating_count' => array(
      'label' => t('Rating count'),
      'type' => 'text',
      'microdata' => TRUE,
    ),
  );
}

/**
 * Get microdata attributes for Fivestar field.
 */
function _fivestar_get_microdata_property_info($entity_type, $entity, $field, $instance) {
  // If microdata module is enabled, attach the microdata attributes the module
  // adds to the entity object.
  if (module_exists('microdata')) {
    $microdata = $entity->microdata[$field['field_name']];
  }
  // If microdata is not enabled, add empty arrays for each property so we
  // don't have to check later in the theme functions.
  else {
    $microdata = array(
      '#attributes' => array(),
    );
    // If Entity API is enabled, we can use that to get the properties.
    // Otherwise, replicate the Entity API logic for getting the properties.
    if (module_exists('entity')) {
      $entity_info = entity_get_all_property_info($entity_type);
    }
    else {
      $info = array();
      $info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']] = array();
      fivestar_property_info_callback($info, $entity_type, $field, $instance, 'fivestar');
      $entity_info = $info[$entity_type]['bundles'][$instance['bundle']]['properties'];
    }
    foreach ($entity_info[$field['field_name']]['property info'] as $property_name => $property) {
      $microdata[$property_name]['#attributes'] = array();
    }
  }

  return $microdata;
}

However, the problem is still existing: token are giving empty fields

awd studio’s picture

@Castor-designs, please, try patch from #11, it should solve this problem.

castor-designs’s picture

Hi @AWD Studio I tried to do just that manually but it does not fit my includes/fivestar.field.inc file.
Like for example line 806 is nowhere near this codeblock:

       'type' => 'text',
       'microdata' => TRUE,
     ),

line 806 in my case is

$info = array();
      $info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']] = array();
      fivestar_property_info_callback($info, $entity_type, $field, $instance, 'fivestar');
      $entity_info = $info[$entity_type]['bundles'][$instance['bundle']]['properties'];
awd studio’s picture

Ok. If it's possible - refill module with current dev-version and apply patch over it.

Or, just replace file "/includes/fivestar.field.inc" (relative to fivestar module), with a file from a link: https://drive.google.com/open?id=1xFDOHgz7bhN44zfoAB4EiBhOpf9NnT9o (it has already patched).

castor-designs’s picture

I downloaded and uploaded your file and it works perfect! Thank you very much for your help. It is much appreciated!

awd studio’s picture

Status: Needs review » Reviewed & tested by the community

@Castor-designs, no problem. Good luck with your projects!

Contributors, please, pay your attention, if it possible.

jaram’s picture

@AWD Studio
I'm waiting for this patch very long time :-) but when dev-version is installed, your patch /includes/fivestar.field.inc is replaced but after insert token
[node:field-hodnoceni:average_rating] is showing ,,96,, - can be 4,8?
in page https://recepty.ekucharka.net/recept/1034-svestkovy-kolac-se-zmolenkou

Jarda

jaram’s picture

My solution

$var=([node:field-hodnoceni:average_rating]/100)*5;
print $var;
awd studio’s picture

@jaram, sorry, my patch doesn't do anything with "average_rating" counting. It solves only tokens "rating_count", "user_rating" and "rating_fivestar".

ykoech’s picture

Thank you, #17 solved it.

NWest’s picture

The patch works great and now you can see the “user_rating output. But how would you get the “user_rating” to output a value of say; 5 instead of 100 percent, or 3 instead of 60 percent, since I want to used a value of 1-5 in the Schema Review field.

awd studio’s picture

@NWest, unfortunately, I don't remember the whole working process of this issue ))
As I can assume - you need to use the common "rating_fivestar" token, because current user's rating have no sense for the search engine (it is always anonymous), if it need to be used for some SEO aims.

hilrap’s picture

@jaram how did you get your aggregate ratingvalue to echo digits from 1 to 5? Mine is only giving the percentage.
Does

$var=([node:field-hodnoceni:average_rating]/100)*5;
print $var;

go into the template.php file?

hilrap’s picture

Does anyone have a solution for this? #24