public function QuantityWidget::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 NumberWidget::settingsForm
File
- modules/
order/ src/ Plugin/ Field/ FieldWidget/ QuantityWidget.php, line 35
Class
- QuantityWidget
- Plugin implementation of the 'commerce_quantity' widget.
Namespace
Drupal\commerce_order\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$step = $this
->getSetting('step');
$element['#element_validate'][] = [
get_class($this),
'validateSettingsForm',
];
$element['allow_decimal'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Allow decimal quantities'),
'#default_value' => $step != '1',
];
$element['step'] = [
'#type' => 'select',
'#title' => $this
->t('Step'),
'#description' => $this
->t('Only quantities that are multiples of the selected step will be allowed.'),
'#default_value' => $step != '1' ? $step : '0.1',
'#options' => [
'0.1' => '0.1',
'0.01' => '0.01',
'0.25' => '0.25',
'0.5' => '0.5',
'0.05' => '0.05',
],
'#states' => [
'visible' => [
':input[name="fields[quantity][settings_edit_form][settings][allow_decimal]"]' => [
'checked' => TRUE,
],
],
],
'#required' => TRUE,
];
return $element;
}