Problem/Motivation

Creating a fivestar widget with less than five stars can be a multistep process, because you cannot, as the Options description says, To delete an option - delete its values in the fields value, label and class and save the rate widget. If you do so on more than one option at a time, it will trigger Drupal\rate\RateWidgetForm::ValidateForm()'s call to $form_state->setError() with Option values have to be unique.

You can get around the issue by deleting one at a time, but that really shouldn't be necessary.

Steps to reproduce

Try creating a new Fivestar Rate widget at /admin/structure/rate/add with less than four stars by following the description text and deleting the label and value from two or more options.

The form will fail validation and output the error message Option values have to be unique.

You can delete one option at time, coming back to resave after each.

Proposed resolution

This looks to me like the code introduced from https://www.drupal.org/project/rate/issues/3267488 went a little too far:
I also got around the issue by adding conditions to the if statement (line 710) surrounding the $form_state->setError(), changing it from if ($settings['value'] == $value){ to if ($settings['value'] == $value && !empty($settings['label']) && $value != '') {, but I doubt this is a proper long-term solution, as I don't know how this change would affect other situations, and Drupal now has proper Form Validation classes which probably offer better paths to follow.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

msypes created an issue. See original summary.

ivnish’s picture

Version: 3.1.0 » 3.3.x-dev

Can confirm this