public function VariationAddToCartFormatter::settingsForm in Commerce Variation Add to Cart 8
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. 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 elements for the formatter settings.
Overrides FormatterBase::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ VariationAddToCartFormatter.php, line 91
Class
- VariationAddToCartFormatter
- Plugin implementation of the 'variation_add_to_cart_form' formatter.
Namespace
Drupal\commerce_variation_add_to_cart\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$attributes = $this->entityQuery
->execute();
$form['show_title'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show variation title.'),
'#default_value' => $this
->getSetting('show_title'),
];
$form['show_quantity'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show quantity box.'),
'#default_value' => $this
->getSetting('show_quantity'),
];
$form['show_price'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show price.'),
'#default_value' => $this
->getSetting('show_price'),
];
$form['show_currency'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show currency.'),
'#default_value' => $this
->getSetting('show_currency'),
];
$form['price_format'] = [
'#type' => 'select',
'#title' => $this
->t('Price format.'),
'#options' => [
'0' => '0',
'2' => '0.00',
],
'#default_value' => $this
->getSetting('price_format'),
];
$form['attributes'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Display the following attributes'),
'#options' => $attributes,
'#default_value' => $this
->getSetting('attributes'),
];
return $form;
}