OrderItemsWidget::extractFormValues() doesn't check for empty #inline_form when $widget_state['form'] === 'add'.

Steps to reproduce from a clean install on PHP >8.4:

Scenario A:

  1. Create a draft order and go to its view page.
  2. Click "Add order items".
  3. Click "Next" while the variation entity reference field is empty.
  4. Click "Save".

Scenario B:

  1. Create a product with a variation.
  2. Create a draft order and go to its view page.
  3. Click "Add order items".
  4. Search for and select the created variation, click "Next", click "Add". The form receives the order items table showing the newly created order item.
  5. Click "Add another" while the variation entity reference field is empty.
  6. Click "Save".

Both scenarios result in WSOD. Observe a warning and a fatal error in the watchdog:

Warning: Undefined array key "#inline_form" in Drupal\commerce_order\Plugin\Field\FieldWidget\OrderItemsWidget->extractFormValues() (line 266 of [...]/commerce/modules/order/src/Plugin/Field/FieldWidget/OrderItemsWidget.php)

Error: Call to a member function getEntity() on null in Drupal\commerce_order\Plugin\Field\FieldWidget\OrderItemsWidget->extractFormValues() (line 268 of [...]/commerce/modules/order/src/Plugin/Field/FieldWidget/OrderItemsWidget.php).

Issue fork commerce-3603974

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ts.ag created an issue. See original summary.

ts.ag’s picture

Status: Active » Needs review
ts.ag’s picture

MR 705 solves the issue for me.

I think the "Next" and "Add another" buttons should be state-controlled to be disabled if the field has no value, same for the "Save" button if there are no added order items. But maybe this should be addressed for all instances of add forms and multivalue form fields in a dedicated issue.

tbkot made their first commit to this issue’s fork.

  • jsacksick committed 86a3ee05 on 3.x authored by ts.ag
    fix: #3603974 WSOD on "Add order items" modal with empty variation field...
jsacksick’s picture

Status: Needs review » Fixed

Thank you!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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