function ShortcutSetForm::form

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

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' => 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);
}

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