You are here

public function EntitySelectWidget::settingsForm in Commerce Core 8.2

Returns a form to configure settings for the widget.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form definition for the widget settings.

Overrides WidgetBase::settingsForm

File

src/Plugin/Field/FieldWidget/EntitySelectWidget.php, line 38

Class

EntitySelectWidget
Plugin implementation of the 'commerce_entity_select' widget.

Namespace

Drupal\commerce\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $formState) {
  $element = [];
  $element['hide_single_entity'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t("Hide if there's only one available entity."),
    '#default_value' => $this
      ->getSetting('hide_single_entity'),
    '#access' => $this->fieldDefinition
      ->isRequired(),
  ];
  $element['autocomplete_threshold'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Autocomplete threshold'),
    '#description' => $this
      ->t('Number of available entities after which the autocomplete is used.'),
    '#default_value' => $this
      ->getSetting('autocomplete_threshold'),
    '#min' => 2,
    '#required' => TRUE,
  ];
  $element['autocomplete_size'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Autocomplete size'),
    '#description' => $this
      ->t('Size of the input field in characters.'),
    '#default_value' => $this
      ->getSetting('autocomplete_size'),
    '#min' => 1,
    '#required' => TRUE,
  ];
  $element['autocomplete_placeholder'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Autocomplete placeholder'),
    '#default_value' => $this
      ->getSetting('autocomplete_placeholder'),
    '#description' => $this
      ->t('Text that will be shown inside the autocomplete field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
  ];
  return $element;
}