Hello

I've installed fivestar on drupal 8, but when I've tried to add a fivestar field to my custom content type I get the error message:

This value should be of the correct primitive type.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mm3 created an issue. See original summary.

myLies’s picture

Can confirm - I've reproduce this on Drupal 8.3

myLies’s picture

and on Drupal 8.1 to
by the way - it's work if you set default value in field settings page

mm3’s picture

I'm not sure if it's possible to have 0 stars back though clicking on one star.

And then if I try to go to the form-display I get a 505 page with this error

PHP Fatal error: Cannot use Drupal\\Component\\Utility\\St
ring as String because 'String' is a special class name in /var/www/alpha/modules/contrib/fivestar/src/Plugin/Field/FieldWidget/SelectWidget.p
hp on line 5, referer: http://alpha/admin/structure/types/manage/breads_pastries/fields

---
commenting out this line in fivestar/src/Plugin/Field/FieldWidget/SelectWidget.php seems to solve this last issue
#use Drupal\Component\Utility\String;

myLies’s picture

looks like It's a core issue https://www.drupal.org/node/2220381

about "PHP Fatal error: Cannot use Drupal\\Component\\Utility\\String as String because 'String' is a special class name"
@mm3 - nice catch! but, it not relate to this issue, may you create a new one?

haunted’s picture

Same problem here.

melonangie’s picture

Im getting the same error when attaching a fivestar field to the file entity, no options are available for "Voting target".

grinder3011’s picture

#melonangie

Yes, I have the same issue.

brooke_heaton’s picture

Getting this issue as well. this_value_should_be-2220381-5.patch did not resolve my issue.

brooke_heaton’s picture

Actually I can't get Fivestar fields to show up whatsoever. Not sure if this bug is to blame.

Im getting the same error when attaching a fivestar field to the file entity, no options are available for "Voting target".

Same issue here but on a node.

floydm’s picture

Yeah, there are a lot of issues at this point. I'm attaching a patch not as the solution to what is going on here, but hopefully to point folks in the right direction.

The "This value should be of the correct primitive type" seems to be related to the first option value being "-" when the value is getting saved in an integer field. Changing it to "0" eliminates the error, though that change may mess up scoring.

There was a JS error trying to invoke $cancel.text(), which isn't a method.

Ajax voting doesn't appear to be firing yet, which I thought might be because drupal.ajax wasn't included as a dependency, but even after adding it I'm not seeing ajax calls.

Also, for visibility I had to edit and resave nodes to see the voting field display.

Shreya Shetty’s picture

Status: Active » Needs review
gg24’s picture

Status: Needs review » Needs work

This patch replaces stars with a rating dropdown which changes the rating functionality. As of now the error comes when we attach the respective field to any entity but if we check field listing for that content type the field gets attach to it and it works as expected.This issue still persists.

Thanks!

nikosal’s picture

I am here to report the same issue with D8.3.1.

PS.
I'd like also to mention, that actually I was using "star rating" in D7, as I was maintaining a site with reviews and allowed only the author of an article to rate. Then I transitioned to D8, star rating is not ported yet, and tried to use this module not actually as a voting tool for all users, but just for the author of the review (they would be able to "vote" instead of "rating"). Alas, this is not working too and my hands are tied.

sharma.amitt16’s picture

I am using Drupal 8.3.2

I have created a custom field type which reuses the managed_file. Everything is working fine. Field is created and custom field settings are also saved. But when I am trying to upload the file on node form, I am getting the error "This value should be of the correct primitive type.".

Below is the widget form code in file mymmodule/Src/Plugin/Field/FieldWidget/CustomFieldWidget.php

public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $field_settings = $this->getFieldSettings();
    //dpm($items[$delta]);

    $desc = t('Upload file. <br> Allowed file extensions: ' . $field_settings['file_extensions'] . '. <br>Max allowed file size: ' . $field_settings['max_filesize'] . '.');

    $element['target_id'] = [
      '#type' => 'managed_file',
      '#title' => $element['#title'],
      '#default_value' => isset($items[$delta]->target_id) ? $items[$delta]->target_id : 0,
      '#description' => $desc,
    ];

    return $element;
  }
antikapital’s picture

Same problem - 8.3.2

But, I have found an alternative, and it works:

https://www.drupal.org/project/votingapi_widgets

swastik1608’s picture

This has been fixed in the follow up issue link - https://www.drupal.org/node/2884270#comment-12118531.
Please review

swastik1608’s picture

Status: Needs work » Needs review
gg24’s picture

Status: Needs review » Needs work

Seems https://www.drupal.org/node/2884270#comment-12118531 issue is a different issue for fivestar. We can handle this in separate one.
Above issue is still active.

Thanks!

Nil.Ned’s picture

I've same problem but this patch doesn't works :-(

vgutekunst’s picture

Same problem here

BarisW’s picture

https://www.drupal.org/project/votingapi_widgets indeed is a great, working alternative! Thanks for the link @antikapital

maaty388’s picture

Status: Needs work » Active

I'm changing status to active because this is still an issue and there is no fix yet.

Nil.Ned’s picture

Changed solution to #22

maaty388’s picture

Priority: Normal » Critical

I'm changing priority to Critical because you cannot use this module. I just made fresh install of Drupal installed this module and when I want to save field it says "This value should be of the correct primitive type.", but if you choose default value error is gone, so this need to be fixed.

maaty388’s picture

I am debugging right now and I think so far the problem is default value should be set 0 instead of - or NULL not sure didn't fix it yet because if this is set to NULL validation fails... Hope it helps

Bala.addweb’s picture

FileSize
22.8 KB

It is validation error for the default value field. I also get the same error but after giving some default value I save the field without an error. PFA screenshot.

DColo’s picture

I tried changing the '-' to '0' in these files and it seems to work. The "correct primitive type" didn't happen when adding fields or saving content with the Fivestar field, and the Fivestar field also appears to now show up for items with no rating (might have to save them first).

src/Element/Fivestar.php:    $options = ['-' => t('Select rating')];
src/Plugin/Field/FieldWidget/SelectWidget.php:       '#empty_value' => '-', 
nkoporec’s picture

Have the same issue on latest drupal(8.4.5) and setting default value clears the issue.Also tried DColo solution and it works, but I think we need to create a patch with a more correct way to get rid of this issue...

maticb’s picture

Made a patch according to #28, also fixed a related if clause in the JS code.

RumyanaRuseva’s picture

Status: Active » Reviewed & tested by the community

The patch looks and works ok.

init90’s picture

Status: Reviewed & tested by the community » Fixed

Looks like the problem already fixed in current dev release of the module. Thanks, everyone!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.