You are here

public function NameListFormatForm::form in Name Field 8

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/NameListFormatForm.php, line 45

Class

NameListFormatForm
Provides a form controller for name list formats.

Namespace

Drupal\name\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $element = parent::form($form, $form_state);
  $element['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Name'),
    '#default_value' => $this->entity
      ->label(),
    '#maxlength' => 255,
    '#required' => TRUE,
  ];
  $element['id'] = [
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Machine-readable name'),
    '#description' => $this
      ->t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'),
    '#disabled' => !$this->entity
      ->isNew(),
    '#default_value' => $this->entity
      ->id(),
    '#machine_name' => [
      'exists' => [
        $this,
        'exists',
      ],
    ],
  ];
  $element['delimiter'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Delimiter'),
    '#default_value' => $this->entity->delimiter,
    '#description' => $this
      ->t('This specifies the delimiter between the second to last and the last name.'),
  ];
  $element['and'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Last delimiter type'),
    '#options' => $this->formatter
      ->getLastDelimitorTypes(),
    '#default_value' => $this->entity->and,
    '#description' => $this
      ->t('This specifies the delimiter between the second to last and the last name.'),
    '#required' => TRUE,
  ];
  $element['delimiter_precedes_last'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Standard delimiter precedes last delimiter'),
    '#options' => $this->formatter
      ->getLastDelimitorBehaviors(),
    '#default_value' => $this->entity->delimiter_precedes_last,
    '#description' => $this
      ->t('This specifies the delimiter between the second to last and the last name. Contextual means that the delimiter is only included for lists with three or more names.'),
    '#required' => TRUE,
  ];
  $options = range(1, 20);
  $options = array_combine($options, $options);
  $element['el_al_min'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Reduce list and append <em>el al</em>'),
    '#options' => [
      0 => $this
        ->t('Never reduce'),
    ] + $options,
    '#default_value' => $this->entity->el_al_min,
    '#description' => $this
      ->t('This specifies a limit on the number of names to display. After this limit, names are removed and the abbrivation <em>et al</em> is appended. This Latin abbrivation of <em>et alii</em> means "and others".'),
    '#required' => TRUE,
  ];
  $element['el_al_first'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Number of names to display when using <em>el al</em>'),
    '#options' => $options,
    '#default_value' => $this->entity->el_al_first,
    '#required' => TRUE,
  ];
  return $element;
}