Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / shortcut / src / ShortcutSetForm.php
1 <?php
2
3 namespace Drupal\shortcut;
4
5 use Drupal\Core\Entity\BundleEntityFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Form handler for the shortcut set entity edit forms.
10  */
11 class ShortcutSetForm extends BundleEntityFormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function form(array $form, FormStateInterface $form_state) {
17     $form = parent::form($form, $form_state);
18
19     $entity = $this->entity;
20     $form['label'] = [
21       '#type' => 'textfield',
22       '#title' => t('Set name'),
23       '#description' => t('The new set is created by copying items from your default shortcut set.'),
24       '#required' => TRUE,
25       '#default_value' => $entity->label(),
26     ];
27     $form['id'] = [
28       '#type' => 'machine_name',
29       '#machine_name' => [
30         'exists' => '\Drupal\shortcut\Entity\ShortcutSet::load',
31         'source' => ['label'],
32         'replace_pattern' => '[^a-z0-9-]+',
33         'replace' => '-',
34       ],
35       '#default_value' => $entity->id(),
36       // This id could be used for menu name.
37       '#maxlength' => 23,
38     ];
39
40     $form['actions']['submit']['#value'] = t('Create new set');
41
42     return $this->protectBundleIdElement($form);
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function save(array $form, FormStateInterface $form_state) {
49     $entity = $this->entity;
50     $is_new = !$entity->getOriginalId();
51     $entity->save();
52
53     if ($is_new) {
54       drupal_set_message(t('The %set_name shortcut set has been created. You can edit it from this page.', ['%set_name' => $entity->label()]));
55     }
56     else {
57       drupal_set_message(t('Updated set name to %set-name.', ['%set-name' => $entity->label()]));
58     }
59     $form_state->setRedirectUrl($this->entity->urlInfo('customize-form'));
60   }
61
62 }