I am using the Condition field (a commerce_plugin_item field) with cardinality unlimited on a node type. This is to reference certain products from a node. I have set the field form widget to the PluginSelectWidget. When I open the node edit page, the widget shows 1 entry with the condition selector set to '- None -'. If I save this form, I get an error:
RuntimeException: The "plugin_configuration" plugin requires the "plugin_id" configuration key in Drupal\commerce\Plugin\Commerce\InlineForm\InlineFormBase->validateConfiguration() (line 89 of modules/contrib/commerce/src/Plugin/Commerce/InlineForm/InlineFormBase.php).
This is using Commerce 2.28 and Drupal 8.9.20
Setting the widget to any other value from the select list works fine.
The cause seems to be the value of the '- None -' option of the selector: this is an empty string (''). In \Drupal\commerce\Plugin\Field\FieldWidget\PluginSelectWidget::formElement the $target_plugin_id variable is tested to be strict NULL, so fails here.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | commerce-pluginselectwidget-broken-none-3254971-10.patch | 719 bytes | johnpitcairn |
Issue fork commerce-3254971
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 #2
finneCreated merge request with patch that sets $target_plugin_id to NULL when it is ''.
Comment #3
finneComment #4
mrweiner commentedHere's the MR: https://git.drupalcode.org/issue/commerce-3254971/-/merge_requests/1. Wasn't linked
Comment #5
mrweiner commentedChanged the MR to check for an empty string value on plugin_id instead of setting it to null.Setting to value to null beforehand seems to break ajax for me, meaning that if a plugin was previously selected, its settings from would not be removed upon selecting "none".EDIT: It didn't work how I thought it did. Sorry about that -- reverted the MR. But still seeing the ajax issue so something else is going on.
Comment #6
mrweiner commentedComment #8
mrweiner commentedAlright pushed a different update to the MR. Still remove the null setting, but then checks
!empty($target_plugin_id)before building the form.That was the issue before -- accidentally checked or instead of and.
Comment #9
mrweiner commentedUploaded the wrong patch.
Comment #10
johnpitcairn commentedPatch fails to apply for testing.
Comment #11
johnpitcairn commentedThis patch should apply, same solution as #9.
Comment #12
johnpitcairn commentedComment #13
johnpitcairn commentedTests green, patch fixes the issue, I can't see any problem with a slightly relaxed plugin id condition.
Setting this to RTBC, it's @mrweiner's 1-line patch, I just rerolled so it applies.
Comment #15
jsacksick commentedCommitted, thanks!