diff --git a/src/Form/FivestarForm.php b/src/Form/FivestarForm.php index 3ceba8d..b3b1369 100644 --- a/src/Form/FivestarForm.php +++ b/src/Form/FivestarForm.php @@ -121,7 +121,12 @@ class FivestarForm extends FormBase { if ($entity->hasField($fivestar_field_name)) { // For votingapi value will be save during save rating value to // field storage. - $entity->set($fivestar_field_name, $form_state->getValue('vote')); + if ($form_state->getValue('vote')) { + $entity->set($fivestar_field_name, $form_state->getValue('vote')); + } + else { + $entity->set($fivestar_field_name, 'cancel'); + } $entity->save(); } } diff --git a/src/Plugin/Field/FieldType/FivestarItem.php b/src/Plugin/Field/FieldType/FivestarItem.php index 1a81321..e09fdad 100644 --- a/src/Plugin/Field/FieldType/FivestarItem.php +++ b/src/Plugin/Field/FieldType/FivestarItem.php @@ -271,7 +271,9 @@ class FivestarItem extends FieldItemBase { } // Add new vote. - $vote_manager->addVote($entity, $vote_rating, $field_settings['vote_type'], $owner->id()); + if ($vote_rating !== 'cancel') { + $vote_manager->addVote($entity, $vote_rating, $field_settings['vote_type'], $owner->id()); + } // Check to see if there is a target entity. If so, add the vote to that // entity as well.