TypeError: Unsupported operand types: string * int in Drupal\weight\Plugin\Field\FieldWidget\WeightSelectorWidget::rangeOptions() (line 44 of /app/web/modules/contrib/weight/src/Plugin/Field/FieldWidget/WeightSelectorWidget.php).

Created on 21 February 2023, almost 2 years ago
Updated 22 February 2023, almost 2 years ago

Problem/Motivation

This error happens because when adding the field in the entity the field "Range" has the type as textfield and it means that the user can put any value there and not only "numbers" so the editors can put letters, special chars, etc.
If the content editors put any value there different than numbers it's definitely a content issue but I think we can use the field type "number" instead of "textfield" and this error will be avoided

Steps to reproduce

  1. Access: "Structure" » "Content types" » Basic Page » "Manage fields" » "Add field" ( /admin/structure/types/manage/page/fields/add-field )
  2. Select "General" » "Weight"
  3. On "Range" field put letters only, example: "asdfg"
  4. Save
  5. Access: /node/add/page
  6. Result:
  7. TypeError: Unsupported operand types: string * int in Drupal\weight\Plugin\Field\FieldWidget\WeightSelectorWidget::rangeOptions() (line 44 of /app/web/modules/contrib/weight/src/Plugin/Field/FieldWidget/WeightSelectorWidget.php).

Proposed resolution

Update the #FormAPI on "Range" field to use fieldtype as "number". It'll fix the root cause because the editor will be forced to select a number

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

🇧🇷Brazil renatog Campinas

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024