function ShortcutSetForm::form

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

Gets the actual form array to be built.

Overrides EntityForm::form

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' => $this->t('Set name'),
    '#description' => $this->t('The new set is created by copying links 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'] = $this->t('Create new set');
  return $this->protectBundleIdElement($form);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.