You are here

public function NameFormatForm::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/NameFormatForm.php, line 52

Class

NameFormatForm
Provides a base form controller for date 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['pattern'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Format'),
    '#default_value' => $this->entity
      ->get('pattern'),
    '#maxlength' => 255,
    '#required' => TRUE,
  ];
  $element['help'] = $this->parser
    ->renderableTokenHelp();
  return $element;
}