Currently the field settings form sets the default value to 80 (4 stars) if a value has not been set. There's a comment that this is "to prevent error during rating settings save." Zero stars is a reasonable default value for the field, especially if it is not a required field. Adding a patch that changes the default value to 0 on the settings form if it hasn't previously been set. As far as I can tell, this isn't causing any issues on save.

It'd also be nice to have a cleaner way to reset a default value back to 0 if it's already been set, but that's probably a separate issue. Right now you need to use the inspector to unhide the hidden select list to choose the no stars option.

CommentFileSizeAuthor
#2 zeroStarsDefaultValue-3136330-2.patch1.21 KBmrweiner

Comments

mrweiner created an issue. See original summary.

mrweiner’s picture

Status: Active » Needs review
StatusFileSize
new1.21 KB
mrweiner’s picture

Title: Don't set non-zero default value for Stars Widget form » Don't set non-zero default value fallback for Stars Widget form
mrweiner’s picture

Status: Needs review » Needs work

hmm, this 0 value doesn't seem to be respected when the widget is rendered.

mrweiner’s picture

Status: Needs work » Needs review

Scratch that -- it actually renders fine. Just needed a cache clear.

init90’s picture

Hi, I added it but don't remember details. I think it really was needed at that moment...
I just tested your patch and haven't got any errors. Tomorrow I'll test it more detailed to ensure that everything is ok and try to find a purpose for adding that check.
It would be cool to remove that hack, thanks.

init90’s picture

Status: Needs review » Reviewed & tested by the community

Before the code was added we got next error "This value should be of the correct primitive type." when saving fivestar field configuration. This check fixed the error.

But later we added a better check in \Drupal\fivestar\Plugin\Field\FieldType\FivestarItem::isEmpty method which fixed the problem in more propper way.

So the code certainly can be removed, thanks @mrweiner

mrweiner’s picture

That makes sense. Great, no problem!

  • TR committed e7553e0 on 8.x-1.x authored by mrweiner
    Issue #3136330 by mrweiner, init90: Don't set non-zero default value...
tr’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks.

Status: Fixed » Closed (fixed)

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