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.

Issue fork commerce-3254971

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

finne created an issue. See original summary.

finne’s picture

Created merge request with patch that sets $target_plugin_id to NULL when it is ''.

finne’s picture

Status: Active » Needs review
mrweiner’s picture

mrweiner’s picture

StatusFileSize
new810 bytes

Changed 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.

mrweiner’s picture

Status: Needs review » Needs work

The last submitted patch, 5: 3254971-pluginselectwidget-broken-none-5.diff, failed testing. View results

mrweiner’s picture

Status: Needs work » Needs review
StatusFileSize
new747 bytes

Alright 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.

mrweiner’s picture

Uploaded the wrong patch.

johnpitcairn’s picture

Component: Other » Commerce
Assigned: finne » johnpitcairn
Status: Needs review » Needs work

Patch fails to apply for testing.

johnpitcairn’s picture

Assigned: johnpitcairn » Unassigned
Status: Needs work » Needs review
StatusFileSize
new719 bytes

This patch should apply, same solution as #9.

johnpitcairn’s picture

Version: 8.x-2.28 » 8.x-2.x-dev
johnpitcairn’s picture

Status: Needs review » Reviewed & tested by the community

Tests 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.

jsacksick’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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