Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is caused by this core bug: #2906113: Select element's #emtpy_value logic doesn't work for configured plugin forms.
The problem in an IEF is that if there's only a single item in the plugin selection field, the configuration subform won't appear because you can't change the value of the select element.
Workaround patch coming.
Comments
Comment #2
joachim CreditAttribution: joachim at Torchbox commentedComment #3
joachim CreditAttribution: joachim at Torchbox commentedUpping this. It's in fact arguably critical, as there is no workaround that is obvious to the average user.
(For someone who knows how FormAPI works - try to submit the form and then the failed validation will have the plugin configuration form elements for the selected plugin type.)
Comment #4
mglamanjoachim is there _any way possible_ to easily reproduce this in tests? Does it only occur within IEF?
We do have
\Drupal\Tests\commerce\FunctionalJavascript\PluginSelectTest
which tests the widget. However it tests againstcommerce_condition
.Since this widget is provided by the Commerce module we need to replicate this bug in a test, I believe. Especially since our contrib ecosystem depends on it (shipping, etc.)
Comment #5
joachim CreditAttribution: joachim as a volunteer commented> is there _any way possible_ to easily reproduce this in tests? Does it only occur within IEF?
You could simply create a form that shows a plugin form element that has one value, and check that it shows a ' -- select one -- ' option as the first option. Having that fixes the problem in any context.
Alternatively, AFAIK IEF can be run without JS, and if the plugin field item also works without JS, you can create an IEF where the inner entity has a plugin item field, and initially, the ' -- select one -- ' option should show, and making a choice and submitting the plugin field item with a value should then show you the plugin configuration form.
Comment #6
joachim CreditAttribution: joachim at Torchbox commentedReroll.
Comment #7
bojanz CreditAttribution: bojanz at Centarro commentedI assume that this bug can be reproduced with License.
Tried to install License to confirm, but the latest beta blew up my test site (#2943829: Error: Call to a member function addConstraint() on null in commerce_license_entity_bundle_field_info_alter() ).
At a glance, I don't understand why the lack of an empty option prevents the configuration form from being shown.
We pass the same $target_plugin_id to both target_plugin_id and target_plugin_configuration in PluginSelectWidget.
So I'd expect the configuration form to work even with a single available plugin option. If it doesn't, then there's a deeper issue at play, and one that we're missing tests for.
Comment #8
bojanz CreditAttribution: bojanz at Centarro commentedComment #9
joachim CreditAttribution: joachim at Torchbox commented> At a glance, I don't understand why the lack of an empty option prevents the configuration form from being shown.
IIRC, it's because when you open the form, the browser automatically selects the first option in the plugin ID dropdown. But the form hasn't *reacted* to that being selected, so the AJAX does not fire, and the configuration subform for that plugin ID is not loaded.
So if the available IDs are Alpha and Beta, and you want to pick Alpha, you have to do this:
1. select Beta
2. wait for AJAX to show you the beta form
3. select Alpha
4. wait for AJAX to show you alpha form
5. now you can configure it.
If there is only one plugin ID listed, then you're screwed, as you can't change the widget to make it notice you've changed it.
Comment #10
bojanz CreditAttribution: bojanz at Centarro commentedBut it's not the browser that's supposed to be selecting anything. We explicitly select the first available plugin via '#default_value' => $target_plugin_id. So the case you're explaining should not be possible with the current code, indicating a deeper problem.
Comment #11
joachim CreditAttribution: joachim at Torchbox commentedHere's a screenshot showing the problem.
This is the 'add product' form for a product whose PV is set to limit to the role license (or the same effect -- don't enable any other license type modules).
The role license provides a configuration form which shows radios with the site's roles, but it's not showing here.
If there were other license types available in the select element, I would have to select another one, then go back to 'role' to get the role config form elements to AJAX in.
With only one option in the select, I am stuck at this point - there is no way to get it to show.
> But it's not the browser that's supposed to be selecting anything. We explicitly select the first available plugin via '#default_value' => $target_plugin_id.
It's good UX to have a neutral option initially selected -- there is even a comment somewhere in FormAPI code that says so, though sadly FormAPI doesn't provide that by default :/