You are here

public function TokenCustomTypeForm::form in Custom Tokens 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides EntityForm::form

File

src/Form/TokenCustomTypeForm.php, line 47

Class

TokenCustomTypeForm
Configure custom settings for this site.

Namespace

Drupal\token_custom\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $token_type = $this->entity;
  $form['name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t("Token type's name"),
    '#description' => $this
      ->t("The token type's readable name"),
    '#default_value' => $token_type
      ->label(),
    '#maxlength' => 255,
    '#required' => TRUE,
  ];
  $form['machineName'] = [
    '#type' => 'machine_name',
    '#title' => $this
      ->t("Token type's machine name"),
    '#description' => $this
      ->t('A unique machine-readable name for this token. It must only contain lowercase letters, numbers, and underscores.'),
    '#default_value' => $token_type
      ->id(),
    '#maxlength' => 32,
    '#machine_name' => [
      'exists' => '\\Drupal\\token_custom\\Entity\\TokenCustomType::load',
      'replace' => '-',
      'replace_pattern' => '[^a-z0-9\\-]+',
    ],
  ];
  $form['description'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Token description'),
    '#description' => $this
      ->t("The token type's description."),
    '#default_value' => $token_type
      ->getDescription(),
    '#required' => TRUE,
  ];
  return $this
    ->protectBundleIdElement($form);
}