3 namespace Drupal\shortcut;
5 use Drupal\Core\Entity\BundleEntityFormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Form handler for the shortcut set entity edit forms.
13 class ShortcutSetForm extends BundleEntityFormBase {
18 public function form(array $form, FormStateInterface $form_state) {
19 $form = parent::form($form, $form_state);
21 $entity = $this->entity;
23 '#type' => 'textfield',
24 '#title' => t('Set name'),
25 '#description' => t('The new set is created by copying items from your default shortcut set.'),
27 '#default_value' => $entity->label(),
30 '#type' => 'machine_name',
32 'exists' => '\Drupal\shortcut\Entity\ShortcutSet::load',
33 'source' => ['label'],
34 'replace_pattern' => '[^a-z0-9-]+',
37 '#default_value' => $entity->id(),
38 // This id could be used for menu name.
42 $form['actions']['submit']['#value'] = t('Create new set');
44 return $this->protectBundleIdElement($form);
50 public function save(array $form, FormStateInterface $form_state) {
51 $entity = $this->entity;
52 $is_new = !$entity->getOriginalId();
56 $this->messenger()->addStatus($this->t('The %set_name shortcut set has been created. You can edit it from this page.', ['%set_name' => $entity->label()]));
59 $this->messenger()->addStatus($this->t('Updated set name to %set-name.', ['%set-name' => $entity->label()]));
61 $form_state->setRedirectUrl($this->entity->urlInfo('customize-form'));