You are here

public function TaxNumberItem::fieldSettingsForm in Commerce Core 8.2

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

modules/tax/src/Plugin/Field/FieldType/TaxNumberItem.php, line 102

Class

TaxNumberItem
Plugin implementation of the 'commerce_tax_number' field type.

Namespace

Drupal\commerce_tax\Plugin\Field\FieldType

Code

public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
  $country_list = \Drupal::service('address.country_repository')
    ->getList();
  $country_list = [
    (string) $this
      ->t('Regions') => [
      'EU' => $this
        ->t('European Union'),
    ],
    (string) $this
      ->t('Countries') => $country_list,
  ];
  $element['countries'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Collect tax numbers for the following countries'),
    '#description' => $this
      ->t('If no countries are selected, all countries will be allowed.'),
    '#options' => $country_list,
    '#default_value' => $this
      ->getSetting('countries'),
    '#multiple' => TRUE,
    '#size' => 10,
  ];
  $element['verify'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Verify the tax number via external web services'),
    '#description' => $this
      ->t('Uses an official service (such as VIES) when one exists.'),
    '#default_value' => $this
      ->getSetting('verify'),
  ];
  $element['allow_unverified'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Accept unverified tax numbers if the verification service is temporarily unavailable'),
    '#description' => $this
      ->t('Merchants can verify the tax number after the order has been placed.'),
    '#default_value' => $this
      ->getSetting('allow_unverified'),
    '#states' => [
      'visible' => [
        ':input[name="settings[verify]"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  return $element;
}