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:
- Create a draft order and go to its view page.
- Click "Add order items".
- Click "Next" while the variation entity reference field is empty.
- Click "Save".
Scenario B:
- Create a product with a variation.
- Create a draft order and go to its view page.
- Click "Add order items".
- Search for and select the created variation, click "Next", click "Add". The form receives the order items table showing the newly created order item.
- Click "Add another" while the variation entity reference field is empty.
- 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
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
Comment #3
ts.ag commentedComment #4
ts.ag commentedMR 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.
Comment #7
jsacksick commentedThank you!