When there is only one plugin of the type used by the field, the field widget just shows the field label and nothing else. This looks completely broken.

Poking at the code, it looks like what's going on is that the widget sets a value, which doesn't output in the form:

    $element['select']['container']['plugin_id'] = array(
      '#type' => 'value',
      '#value' => $this->getSelectedPlugin()->getPluginId(),
    );

This is bad on two counts:

a) it's really bad UX to show something that looks broken. If there is only one option that must be selected, show it and disable the form element
b) it's NOT the only option anyway, as if the field is not required the user could select nothing.

Comments

joachim created an issue. See original summary.

joachim’s picture

I think the special handling for a single plugin should just be removed. Options fields in core don't hide themselves when there is only one option: they show either:

- None -
Foo

or

- Select a value - 
Foo

It could be there's some special voodoo going on to do with the plugin form... but in the absence of code docs explaining that, I'm going to assume there isn't any.

Let's see what the test bot says!

Status: Needs review » Needs work

The last submitted patch, 2: 3024616-2.plugin.plugin-field-widget-looks-broken-when-theres-only-one-plugin-available.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

lammensj’s picture

Status: Needs work » Needs review
StatusFileSize
new4.16 KB

Updated the patch for version 8.x-2.7.

Status: Needs review » Needs work

The last submitted patch, 4: 3024616-4.plugin.plugin-field-widget-looks-broken-when-theres-only-one-plugin-available.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

lukasss’s picture

I confirm this!
It's just confusing...

ckaotik’s picture

This behavior is - in theory - configurable. However, it's not yet exposed anywhere, see #2822336: Plugin selector field widget configuration.