Less Than Four FiveStar widget Empty Values Duplicate

Created on 14 June 2024, 5 months ago

Problem/Motivation

Creating a fivestar widget with less than five stars can be a multistep process, because you cannot, as the Options description says, 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

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

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

πŸ› Bug report
Status

Active

Version

3.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States msypes

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024