You are here

public function NameFormatter::settingsForm in Name Field 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/NameFormatter.php, line 165

Class

NameFormatter
Plugin implementation of the 'name' formatter.

Namespace

Drupal\name\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $elements['format'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Name format'),
    '#default_value' => $this
      ->getSetting('format'),
    '#options' => name_get_custom_format_options(),
    '#required' => TRUE,
  ];
  $elements['list_format'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('List format'),
    '#default_value' => $this
      ->getSetting('list_format'),
    '#empty_option' => $this
      ->t('-- individually --'),
    '#options' => name_get_custom_list_format_options(),
  ];
  $elements['markup'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Markup'),
    '#default_value' => $this
      ->getSetting('markup'),
    '#options' => $this->parser
      ->getMarkupOptions(),
    '#description' => $this
      ->t('This option wraps the individual components of the name in SPAN elements with corresponding classes to the component.'),
    '#required' => TRUE,
  ];
  if (!empty($this->fieldDefinition
    ->getTargetBundle())) {
    $elements['link_target'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Link Target'),
      '#default_value' => $this
        ->getSetting('link_target'),
      '#empty_option' => $this
        ->t('-- no link --'),
      '#options' => $this
        ->getLinkableTargets(),
    ];
    $elements += $this
      ->getNameAdditionalPreferredSettingsForm($form, $form_state);
  }
  return $elements;
}