Commerce Entity Select

Drupal Commerce has a field widget, Commerce Entity Select that does some interesting things with the field and form API.

Source

namespace Drupal\commerce\Plugin\Field\FieldWidget;

/**
 * Plugin implementation of the 'commerce_entity_select' widget.
 *
 * @FieldWidget(
 *   id = "commerce_entity_select",
 *   label = @Translation("Entity select"),
 *   field_types = {
 *     "entity_reference"
 *   },
 *   multiple_values = TRUE
 * )
 */
class EntitySelectWidget extends WidgetBase {}

 

Here's the widget settings form:

Commerce Entity Select

Here are the options you can change for the widget:

  1. If there is only one entity to select, hide the widget and select by default.
  2. Autocomplete threshold - Widget shows checkboxes if there are fewer than this many entities.
  3. Autocomplete size - field width.
  4. Autocomplete placeholder - dummy text.