You are here

public function ShortcutSetForm::form in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/shortcut/src/ShortcutSetForm.php \Drupal\shortcut\ShortcutSetForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

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

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

File

core/modules/shortcut/src/ShortcutSetForm.php, line 18

Class

ShortcutSetForm
Form handler for the shortcut set entity edit forms.

Namespace

Drupal\shortcut

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $entity = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => t('Set name'),
    '#description' => t('The new set is created by copying items from your default shortcut set.'),
    '#required' => TRUE,
    '#default_value' => $entity
      ->label(),
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#machine_name' => [
      'exists' => '\\Drupal\\shortcut\\Entity\\ShortcutSet::load',
      'source' => [
        'label',
      ],
      'replace_pattern' => '[^a-z0-9-]+',
      'replace' => '-',
    ],
    '#default_value' => $entity
      ->id(),
    // This id could be used for menu name.
    '#maxlength' => 23,
  ];
  $form['actions']['submit']['#value'] = t('Create new set');
  return $this
    ->protectBundleIdElement($form);
}