You are here

protected function NameAdditionalPreferredTrait::getNameAdditionalPreferredSettingsForm in Name Field 8

Returns a form for the default settings defined above.

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.

2 calls to NameAdditionalPreferredTrait::getNameAdditionalPreferredSettingsForm()
NameFormatter::settingsForm in src/Plugin/Field/FieldFormatter/NameFormatter.php
Returns a form to configure settings for the formatter.
NameItem::fieldSettingsForm in src/Plugin/Field/FieldType/NameItem.php
Returns a form for the field-level settings.

File

src/Traits/NameAdditionalPreferredTrait.php, line 38

Class

NameAdditionalPreferredTrait
Name form for preferred and alternative settings trait.

Namespace

Drupal\name\Traits

Code

protected function getNameAdditionalPreferredSettingsForm(array &$form, FormStateInterface $form_state) {
  $elements = [];
  $elements['preferred_field_reference'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Preferred component source'),
    '#default_value' => $this
      ->getSetting('preferred_field_reference'),
    '#empty_option' => $this
      ->getEmptyOption(),
    '#options' => $this
      ->getAdditionalSources(),
    '#description' => $this
      ->t('A data source to use as the preferred given name within the name formats. A common use-case would be for a users nickname.<br>i.e. "q" and "v", plus the conditional "p", "d" and "D" name format options.'),
  ];
  $elements['preferred_field_reference_separator'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Preferred component source multivalue separator'),
    '#default_value' => $this
      ->getSetting('preferred_field_reference_separator'),
    '#description' => $this
      ->t('Used to separate multi-value items in an inline list.'),
    '#states' => [
      'invisible' => [
        ':input[name$="[preferred_field_reference]"]' => [
          'value' => '',
        ],
      ],
    ],
  ];
  $elements['alternative_field_reference'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Alternative component source'),
    '#default_value' => $this
      ->getSetting('alternative_field_reference'),
    '#empty_option' => $this
      ->getEmptyOption(),
    '#options' => $this
      ->getAdditionalSources(),
    '#description' => $this
      ->t('A data source to use as the alternative component within the name formats. Possible use-cases include; providing a custom fully formatted name alternative to use in citations; a separate field for a users creditatons / post-nominal letters.<br>i.e. "a" and "A" name format options.'),
  ];
  $elements['alternative_field_reference_separator'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Alternative component source multivalue separator'),
    '#default_value' => $this
      ->getSetting('alternative_field_reference_separator'),
    '#description' => $this
      ->t('Used to separate multi-value items in an inline list.'),
    '#states' => [
      'invisible' => [
        ':input[name$="[alternative_field_reference]"]' => [
          'value' => '',
        ],
      ],
    ],
  ];
  return $elements;
}