You are here

public function PriceItem::fieldSettingsForm in Price 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldType/PriceItem.php \Drupal\price\Plugin\Field\FieldType\PriceItem::fieldSettingsForm()
  2. 3.x src/Plugin/Field/FieldType/PriceItem.php \Drupal\price\Plugin\Field\FieldType\PriceItem::fieldSettingsForm()
  3. 2.x src/Plugin/Field/FieldType/PriceItem.php \Drupal\price\Plugin\Field\FieldType\PriceItem::fieldSettingsForm()
  4. 3.0.x src/Plugin/Field/FieldType/PriceItem.php \Drupal\price\Plugin\Field\FieldType\PriceItem::fieldSettingsForm()

Returns a form for the field-level settings.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

array The form definition for the field settings.

Overrides FieldItemBase::fieldSettingsForm

File

src/Plugin/Field/FieldType/PriceItem.php, line 106

Class

PriceItem
Plugin implementation of the 'price' field type.

Namespace

Drupal\price\Plugin\Field\FieldType

Code

public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
  $currencies = \Drupal::entityTypeManager()
    ->getStorage('price_currency')
    ->loadMultiple();
  $currency_codes = array_keys($currencies);
  $element = [];
  $element['available_currencies'] = [
    '#type' => count($currency_codes) < 10 ? 'checkboxes' : 'select',
    '#title' => $this
      ->t('Available currencies'),
    '#description' => $this
      ->t('If no currencies are selected, all currencies will be available.'),
    '#options' => array_combine($currency_codes, $currency_codes),
    '#default_value' => $this
      ->getSetting('available_currencies'),
    '#multiple' => TRUE,
    '#size' => 5,
  ];
  $element['allow_negative'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow negative prices'),
    '#default_value' => $this
      ->getSetting('allow_negative'),
  ];
  return $element;
}