You are here

public function TelephoneFormatter::settingsForm in Telephone Formatter 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/TelephoneFormatter.php, line 104

Class

TelephoneFormatter
Plugin implementation of the 'telephone_formatter' formatter.

Namespace

Drupal\telephone_formatter\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements['format'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Format'),
    '#description' => $this
      ->t('List of available formats'),
    '#default_value' => $this
      ->getSetting('format'),
    '#options' => self::availableFormats(),
  ];
  $elements['link'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Link'),
    '#description' => $this
      ->t('Format as link'),
    '#default_value' => $this
      ->getSetting('link'),
  ];
  $elements['default_country'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Default country'),
    '#description' => $this
      ->t('If field allows internal telephone numbers you can choose which country this number belongs to by default. It is highly advised to enable telephone validation for this field to ensure that telephone number is valid and can be parsed and reformatted.'),
    '#default_value' => $this
      ->getSetting('default_country'),
    '#options' => [
      NULL => $this
        ->t('- Do not use default country -'),
    ] + $this->countryManager
      ->getList(),
  ];
  return $elements;
}