Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / linkit / src / Form / Profile / FormBase.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\linkit\Form\Profile\FormBase.
6  */
7
8 namespace Drupal\linkit\Form\Profile;
9
10 use Drupal\Core\Entity\EntityForm;
11 use Drupal\Core\Form\FormStateInterface;
12
13 /**
14  * Base form for profile add and edit forms.
15  */
16 abstract class FormBase extends EntityForm {
17
18   /**
19    * The entity being used by this form.
20    *
21    * @var \Drupal\linkit\ProfileInterface
22    */
23   protected $entity;
24
25   /**
26    * {@inheritdoc}
27    */
28   public function form(array $form, FormStateInterface $form_state) {
29     $form['label'] = [
30       '#type' => 'textfield',
31       '#title' => $this->t('Profile Name'),
32       '#default_value' => $this->entity->label(),
33       '#description' => $this->t('The human-readable name of this  profile. This name must be unique.'),
34       '#required' => TRUE,
35       '#size' => 30,
36     ];
37
38     $form['id'] = [
39       '#type' => 'machine_name',
40       '#default_value' => $this->entity->id(),
41       '#machine_name' => [
42         'exists' => ['\Drupal\linkit\Entity\Profile', 'load']
43       ],
44       '#disabled' => !$this->entity->isNew(),
45     ];
46
47     $form['description'] = [
48       '#type' => 'textarea',
49       '#title' => $this->t('Description'),
50       '#default_value' => $this->entity->getDescription(),
51       '#description' => $this->t('The text will be displayed on the <em>profile collection</em> page.'),
52     ];
53
54     $form['additional_settings'] = array(
55       '#type' => 'vertical_tabs',
56       '#weight' => 99,
57     );
58
59     return parent::form($form, $form_state);
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function save(array $form, FormStateInterface $form_state) {
66     $linkit_profile = $this->entity;
67
68     // Prevent leading and trailing spaces in linkit profile labels.
69     $linkit_profile->set('label', trim($linkit_profile->label()));
70
71     $status = $linkit_profile->save();
72     $edit_link = $this->entity->link($this->t('Edit'));
73     switch ($status) {
74       case SAVED_NEW:
75         drupal_set_message($this->t('Created new profile %label.', ['%label' => $linkit_profile->label()]));
76         $this->logger('linkit')->notice('Created new profile %label.', ['%label' => $linkit_profile->label(), 'link' => $edit_link]);
77         $form_state->setRedirect('linkit.matchers', [
78           'linkit_profile' => $linkit_profile->id(),
79         ]);
80         break;
81
82       case SAVED_UPDATED:
83         drupal_set_message($this->t('Updated profile %label.', ['%label' => $linkit_profile->label()]));
84         $this->logger('linkit')->notice('Updated profile %label.', ['%label' => $linkit_profile->label(), 'link' => $edit_link]);
85         $form_state->setRedirectUrl($linkit_profile->urlInfo('edit-form'));
86         break;
87     }
88   }
89
90 }